旧版断言模式


旧版断言模式在以下方法中使用抽象相等比较

要使用旧版断言模式:

const assert = require('assert');

尽可能改用严格断言模式。 否则,抽象相等比较可能会导致意外的结果。 对于 assert.deepEqual() 尤其如此,其比较规则很宽松:

// 注意:这不会抛出 AssertionError!
assert.deepEqual(/a/gi, new Date());

Legacy assertion mode uses the Abstract Equality Comparison in:

To use legacy assertion mode:

const assert = require('assert');

Whenever possible, use the strict assertion mode instead. Otherwise, the Abstract Equality Comparison may cause surprising results. This is especially true for assert.deepEqual(), where the comparison rules are lax:

// WARNING: This does not throw an AssertionError!
assert.deepEqual(/a/gi, new Date());