我在测试时对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)