我尝试用deepEqual (最新版本)来断言should.js,但没有取得任何成功。我可以使用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'当然可以。现在来看一下should,我看到它是一个getter:
> Object.getOwnPropertyDescriptor(Object.prototype, 'should')
{ get: [Function],
set: [Function],
enumerable: false,
configurable: true }既然它是个好东西,我怎么检查它的钥匙呢?这几乎是可行的:
> 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]应该文档甚至根本没有提到deepEqual,这真的让我感到困惑。更令人困惑的是,当我在节点REPL上输入deepEqual时,我确实看到了一个should。但据我所知,它被埋在一个ok元素中。
TL;DR:我如何称呼assertEqual或与should等价的
发布于 2013-10-07 22:13:01
我认为您应该(双关意)使用eql方法。
https://github.com/visionmedia/should.js/#eql
({ foo: 'bar' }).should.eql({ foo: 'bar' })https://stackoverflow.com/questions/19235374
复制相似问题