Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用should.js执行deepEqual断言?_Javascript_Node.js_Should.js_Deepequals - Fatal编程技术网

Javascript 如何使用should.js执行deepEqual断言?

Javascript 如何使用should.js执行deepEqual断言?,javascript,node.js,should.js,deepequals,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

我试图用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'
既然它是一个getter,我如何检查它的键?这几乎奏效了:

> Object.keys(Object.prototype.should)
[ 'obj' ]
但后来我明白了

> Object.getOwnPropertyDescriptor(should.obj)
{ value: undefined,
  writable: false,
  enumerable: false,
  configurable: false }
所以我在这一点上有点困惑。我只是想看看接下来会发生什么事情

> assert = require('assert')
> assert.deepEqual
[Function: deepEqual]
我这样做了,它说,
should.js
从字面上扩展了节点的断言模块,但节点的断言确实允许
deepEqual

> assert = require('assert')
> assert.deepEqual
[Function: deepEqual]
应该文档甚至根本没有提到
deepEqual
,这让我很困惑。更让人困惑的是,当我在节点REPL上输入
should
时,我确实看到了一个
deepEqual
。但据我所知,它被隐藏在一个
ok
元素中

TL;DR:我如何调用
assertEqual
或它在
should
中的等价物?

我认为您应该(双关语)使用
eql
方法

({ foo: 'bar' }).should.eql({ foo: 'bar' })