来自 chai-as-promised 的文档
(2 + 2).should.equal(4); // becomes return Promise.resolve(2 + 2).should.eventually.equal(4); expect({ foo: "bar" }).to.have.property("foo"); // becomes return expect(Promise.resolve({ foo: "bar" })).to.eventually.have.property("foo");
但如果我尝试
import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import dirtyChai from 'dirty-chai';
import chaiAsPromised from 'chai-as-promised';
chai.use(sinonChai);
chai.use(dirtyChai);
chai.use(chaiAsPromised);
//...
it.only('test', function() {
return expect(Promise.resolve({ foo: 'bar' })).to.eventually.have.property('foo');
});
我得到了这个断言错误:
AssertionError: expected {} to have a property 'foo'
我用不同的用例和断言尝试了它,但它总是一样的,从中出来expect(promise)
的总是一个空对象。
知道为什么吗?
我用
"chai-as-promised": "6.0.0",
"chai": "^3.5.0",
"dirty-chai": "^1.2.2",
"mocha": "3.2.0",
"sinon": "^1.17.3",
"sinon-chai": "^2.8.0"