2013-10-07 31 views
9

我試圖用should.js(最新版本)做一個deepEqual斷言,並沒有取得任何成功。我可以使用equal而不是deepEqual。事實上,我看到沒有deepEqual方法。如何用should.js做一個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' 

很公平。現在尋找到should,我看到它是一個getter:

> Object.getOwnPropertyDescriptor(Object.prototype, 'should') 
{ get: [Function], 
    set: [Function], 
    enumerable: false, 
    configurable: true } 

既然是一個getter,如何我檢查它的鑰匙?這幾乎工程:

> Object.keys(Object.prototype.should) 
[ 'obj' ] 

但後來我看到

> Object.getOwnPropertyDescriptor(should.obj) 
{ value: undefined, 
    writable: false, 
    enumerable: false, 
    configurable: false } 

所以我寧願停留在這一點上。我只想看看什麼東西可以遵循should

read the docs和它說,should.js字面上擴展節點的斷言模塊,但節點的斷言確實允許deepEqual

> assert = require('assert') 
> assert.deepEqual 
[Function: deepEqual] 

應該docs甚至沒有提到deepEqual在所有,這真的讓我感到困惑。爲了讓事情更加令人困惑,當我在節點REPL上輸入should時,我做了看到一個deepEqual。據我所知,它被埋在了一個ok元素中。

TL; DR:我如何撥打assertEqual或同等電話should

回答