Node中的assert.equal
assert.equal(actual, expected[, message])
参数类型
- actual:any
- expected: any
- message: string|Error
严格模式
An alias of assert.strictEqual().
官方解释
Tests shallow, coercive equality between the actual and expected parameters using the Abstract Equality Comparison ( == ). NaN is special handled and treated as being identical in case both sides are NaN.
使用抽象的相等比较(==)测试实际参数和期望参数之间的浅层强制相等。如果两边都是NaN,则NaN将被特殊处理并视为相同的
const assert = require('assert');
assert.equal(1, 1);
// OK, 1 == 1
assert.equal(1, '1');
// OK, 1 == '1'
assert.equal(NaN, NaN);
// OK
assert.equal(1, 2);
// AssertionError: 1 == 2
assert.equal({ a: { b: 1 } }, { a: { b: 1 } });
// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }
If the values are not equal, an AssertionError is thrown with a message property set equal to the value of the message parameter. If the message parameter is undefined, a default error message is assigned. If the message parameter is an instance of an Error then it will be thrown instead of the AssertionError.
如果两个值不相等,则抛出AssertionError,并将消息属性设置为等于消息参数的值。如果message参数未定义,则会分配一个默认的错误消息。如果消息参数是一个错误实例,那么将抛出该错误,而不是AssertionError。