屏幕快照 2021-06-10 下午4.34.34.png
示例:
const assert = require('assert').strict
assert.deepStrictEqual({ a: 1 }, { a: '1' });
//AssertionError [ERR_ASSERTION]: Input A expected to strictly deep-equal input B:
assert.notDeepStrictEqual({ a: 1 }, { a: '1' });
//ok
assert.fail('tttt')
//AssertionError [ERR_ASSERTION]: tttt
assert.fail(new RangeError('越界错误'))
//RangeError: 越界错误
assert.ifError(3)
// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 3
assert.throws(() => {
throw new Error('sdsa')
})
//ok
- 尽量使用严格模式