Sinon-Mongoose不与Sinon 9合作



sinon-mongoose = 2.3.0不能使用sinon 9

我的代码如下

// test.js
const sinon = require('sinon');
require('sinon-mongoose');
const blog = require('../blog/blog.model');
it('GET Blogs /blogs/ls', (done) => {
sinon
.mock(blog)
.expects('find')
.chain('populate')
.resolves([]);
request(app)
.get('/blogs/ls')
.expect(200)
.end((err, res) => {
if (err) throw done(err);
done();
});
});

错误是

TypeError: Cannot set property 'mock' of undefined

还有其他选择或库可以在摩卡中模拟模型吗?

好的,我在 sinon-mongoose 中解决了这个问题,有一个修复程序但没有在 npm 上发布,所以我直接使用了固定文件。只有一个文件。

应用修复的步骤:

  1. 下载此文件 https://github.com/mir4ef/sinon-mongoose/blob/feature/sinon-v8-compatible/lib/index.js
  2. 将其重命名为sinon-mongoose
  3. 将其从本地文件导入到测试用例中。
const sinon = require('sinon');
require('../sinon-mongoose');
  1. 它正在工作

最新更新