assert.notEqual()
添加版本:1.0.0.
描述
notEqual( actual, expected, message = "" )
一个松散的不等比较,检查两个值之间的非严格差异。
名称 | 描述 |
---|---|
实际 |
正在测试的表达式 |
预期 |
已知比较值 |
message (字符串) |
简短描述 |
notEqual
断言使用简单的反向比较运算符 (!=
) 来比较实际值和预期值。当它们不相等时,断言通过;否则,断言失败。当它失败时,除了给定的消息外,实际值和预期值都会显示在测试结果中。
assert.equal()
可用于测试相等性。
assert.notStrictEqual()
可用于测试严格不等性。
示例
最简单的断言示例
QUnit.test('passing example', assert => {
const result = '2';
// succeeds, 1 and 2 are different.
assert.notEqual(result, 1);
});
QUnit.test('failing example', assert => {
const result = '2';
// fails, the number 2 and the string "2" are considered equal when
// compared loosely. Use `assert.notStrictEqual` to consider them different.
assert.notEqual(result, 2);
});