Node中的assert.equal

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。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值