我正在尝试使用 Mocha、Sinon 和 chai 测试我的 node.js 代码。
var callback = function (err, resultSet) {
should.exist(resultSet);
stubbedExecuteSqlQuery.should.be.called;
done();
};
stubbedExecuteSqlQuery.yields(null, expectedResultSet);
db.getResults(param1,param2, user, callback);
当上面的代码执行时,它会抛出一个错误:
Invalid Chai property: called. Did you mean "all"?
代码过去在 chai 版本上运行良好
^3.5.0
,但在我最近的软件包升级到^4.1.2
之后,代码已停止工作并开始抛出此类错误。
我尝试在互联网上搜索它,但找不到任何有用的信息。
任何帮助将不胜感激。预先感谢!
我遇到了类似的问题,我认为这与使用 .yields 有关 我最终使用了 .calledOnce 。尝试以下操作:
assert(stubbedExecuteSqlQuery.calledOnce);
这样做的好处是,如果需要,你可以做 .叫Twice 等..
从 chai 3 -> 4 升级时我也遇到了这个问题。
我解决这个问题的方法是在每个受影响的测试文件中具体说明我的导入:
import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
chai.use(sinonChai);
const { expect } = chai;
....
expect(setCookieSpy).to.have.been.called;