相关疑难解决方法(0)

对于异步测试和挂钩,确保调用"done()"; 如果返回Promise,请确保它已解决

我在测试时对nodejs进行了测试,我得到了未声明的完成函数的错误.

Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
Run Code Online (Sandbox Code Playgroud)

我的测试代码是,我已完成回调但仍然收到错误来调用 done();

    it('remove existing subdocument', (done) => {
    const Vic = new User({
      name: 'Vic',
      posts: [{ title: 'Leaning Nodejs' }]
    });

    vic.save()
      .then(() => User.findOne({ name: 'Vic' }))
      .then((user) => {
        const post = user.posts[0];
        post.remove();
        return user.save();
      })
      .then(() => User.findOne({ name: 'Vic' }))
      .then((user) => {
        assert(user.posts.length === 0);
        done();
      });
  });
Run Code Online (Sandbox Code Playgroud)

mocha.js node.js

27
推荐指数
5
解决办法
3万
查看次数

标签 统计

mocha.js ×1

node.js ×1