在nodejs中使用断言模块的严格模式
strict mode using assert module in nodejs
能否请您帮助我理解以下错误:
js content:
const assert = require('assert').strict;
var res = assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
Error:
TypeError: Cannot read property 'deepEqual' of undefined
My understanding:
根据 Nodejs
文档,在加载“assert
”模块时使用 .strict
将使我们处于限制模式,这会导致 assert.deepEqual()
和 assert.deepStrictEqual()
与此描述相同。输出应该是
"errors.AssertionError"
请指导我?
确保您使用的是节点 v.9.10.1 v. 9.10.1 assert API since strict
functionality is not compatible with previous node versions. Here is node v. 8.11.1 and v. 8.11.1 assert API,这样您就可以看到 strict
不可用。
在我的例子中,它使用 node v. 9.10.1 工作正常。
const assert = require('assert').strict;
// check your node version
console.log(process.version)
assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
v9.10.1
assert.js:49
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Input A expected to deepStrictEqual input B:
+ expected - actual ... Lines skipped
[
[
...
2,
- 3
+ '3'
]
...
5
]
能否请您帮助我理解以下错误:
js content:
const assert = require('assert').strict;
var res = assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
Error:
TypeError: Cannot read property 'deepEqual' of undefined
My understanding:
根据 Nodejs
文档,在加载“assert
”模块时使用 .strict
将使我们处于限制模式,这会导致 assert.deepEqual()
和 assert.deepStrictEqual()
与此描述相同。输出应该是
"errors.AssertionError"
请指导我?
确保您使用的是节点 v.9.10.1 v. 9.10.1 assert API since strict
functionality is not compatible with previous node versions. Here is node v. 8.11.1 and v. 8.11.1 assert API,这样您就可以看到 strict
不可用。
在我的例子中,它使用 node v. 9.10.1 工作正常。
const assert = require('assert').strict;
// check your node version
console.log(process.version)
assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);
v9.10.1
assert.js:49
throw new AssertionError(obj);
^
AssertionError [ERR_ASSERTION]: Input A expected to deepStrictEqual input B:
+ expected - actual ... Lines skipped
[
[
...
2,
- 3
+ '3'
]
...
5
]