Ray*_*oal 10 javascript node.js should.js deepequals
我试图用should.js(最新版本)做一个deepEqual断言但没有取得任何成功.我可以让事情与之合作,equal
但不是deepEqual
.事实上,我发现没有deepEqual
方法.
这是我尝试过的:
> require('should')
{...}
> > var x = Number(8)
undefined
> x.should.equal(8)
{ obj: 8 }
> x.should.equal(9)
AssertionError: expected 8 to equal 9
at ....
> x.should.deepEqual(8)
TypeError: Object #<Object> has no method 'deepEqual'
Run Code Online (Sandbox Code Playgroud)
很公平.现在看should
,我看到它是一个吸气剂:
> Object.getOwnPropertyDescriptor(Object.prototype, 'should')
{ get: [Function],
set: [Function],
enumerable: false,
configurable: true }
Run Code Online (Sandbox Code Playgroud)
既然它是一个吸气剂,我该如何检查其键?这几乎有效:
> Object.keys(Object.prototype.should)
[ 'obj' ]
Run Code Online (Sandbox Code Playgroud)
但后来我明白了
> Object.getOwnPropertyDescriptor(should.obj)
{ value: undefined,
writable: false,
enumerable: false,
configurable: false }
Run Code Online (Sandbox Code Playgroud)
所以我现在很困惑.我想知道会发生什么事情should
.
我确实 阅读了文档,它说should.js
字面上扩展了节点的断言模块,但节点的断言确实允许deepEqual
.
> assert = require('assert')
> assert.deepEqual
[Function: deepEqual]
Run Code Online (Sandbox Code Playgroud)
应该文档甚至根本没有提到deepEqual
,这让我很困惑.为了让事情变得更加混乱,我确实deepEqual
在进入should
节点REPL 时看到了.但就ok
我所知,它被埋在一个元素中.
TL; DR:我如何打电话assertEqual
或从中等同should
?
pll*_*lee 14
我认为你应该(双关语)使用这种eql
方法.
https://github.com/visionmedia/should.js/#eql
({ foo: 'bar' }).should.eql({ foo: 'bar' })
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3237 次 |
最近记录: |