旧版断言模式


旧版断言模式在以下方法中使用 == 运算符

要使用旧版断言模式:

import assert from 'node:assert';const assert = require('node:assert');

旧版断言模式可能会产生意外的结果,尤其是在使用 assert.deepEqual() 时:

// 注意:在旧版断言模式下这不会抛出 AssertionError!
assert.deepEqual(/a/gi, new Date());

Legacy assertion mode uses the == operator in:

To use legacy assertion mode:

import assert from 'node:assert';const assert = require('node:assert');

Legacy assertion mode may have surprising results, especially when using assert.deepEqual():

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