Mocha chai变得悬而未决,其中的expect()在其中()中间件func()块

时间:2016-02-19 07:33:42

标签: node.js unit-testing express mocha chai

我不知道为什么但是这会将成功返回为挂起,但失败成功返回使用mocha进行测试失败

describe('createToken', function() {

    it('should return the token', utils.createToken('somestring', function(err, auth){

        expect(typeof auth.token).to.equal('string'); // pending but should be success
        expect(err).to.equal(null); // pending
        expect(true).to.equal(false); // fail

    }));
})

我和这段代码有什么问题?提前谢谢。

1 个答案:

答案 0 :(得分:1)

尝试使用done()进行测试,如下所示

describe('createToken', function() {

    it('should return the token', function(done) {
      utils.createToken('somestring', function(err, auth){

        expect(typeof auth.token).to.equal('string'); // pending but should be success
        expect(err).to.equal(null); // pending
        expect(true).to.equal(false); // fail
        done();

      })
   });
})