首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >sinon-mongoose不支持sinon 9

sinon-mongoose不支持sinon 9
EN

Stack Overflow用户
提问于 2020-06-30 16:41:21
回答 1查看 335关注 0票数 2

sinon-mongoose = 2.3.0不支持sinon 9

我的代码如下

代码语言:javascript
复制
// 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();
      });
  });

错误是

代码语言:javascript
复制
TypeError: Cannot set property 'mock' of undefined

在mocha中模拟模型有没有其他的选项或库?

EN

回答 1

Stack Overflow用户

发布于 2020-06-30 17:18:15

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

应用修复的步骤:

将此文件从本地文件https://github.com/mir4ef/sinon-mongoose/blob/feature/sinon-v8-compatible/lib/index.js

  • Rename it sinon-mongoose

  • Import
  1. 下载到您的测试用例中。

代码语言:javascript
复制
const sinon = require('sinon');
require('../sinon-mongoose');

  1. it is working
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62653523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档