Mocha-chai从Node中的生成器抛出错误

时间:2016-06-05 08:29:41

标签: node.js promise ecmascript-6 mocha generator

此代码here抛出错误

Error: timeout of 2000ms exceeded. Ensure the done() callback is being called in this test.
    at null.<anonymous> (C:\wamp\www\clearanceForm\node_modules\mocha\lib\runnable.js:226:19)

但当我改变第50行以测试哪些不应该通过时,比如

savedUser.should.not.eql(foundUser);

错误不再被抛出并且...测试通过。这是为什么?怎么了?

编辑: 我已经修改了asyncTest来输出对象:

function *asyncTest(first, second) {
    let sth = new test_model({first: first, second: second});
    let savedUser = yield asyncPromiseUtil(sth.save());
    let foundUser = yield asyncPromiseUtil(test_model.findById(savedUser._id));
    console.log(savedUser);
    console.log(foundUser);
    savedUser.should.not.eql(foundUser);
    done();
}

这是输出:

{ _id: 5753e798b80a84781a86d024,
  second: '123',
  first: 'asda',
  __v: 0 }
{ __v: 0,
  second: '123',
  first: 'asda',
  _id: 5753e798b80a84781a86d024 }

0 个答案:

没有答案