Mocha chai 在 it() 块中等待 expect() 和中间件 func()
Mocha chai becomes pending with expect() inside it() block with middleware func()
我不知道为什么,但这 returns 成功未决,但失败成功 returns 使用 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
}));
})
我和这段代码有什么问题?提前致谢。
尝试使用 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();
})
});
})
我不知道为什么,但这 returns 成功未决,但失败成功 returns 使用 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
}));
})
我和这段代码有什么问题?提前致谢。
尝试使用 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();
})
});
})