【问题标题】:Mocha chai becomes pending with expect() inside it() block with middleware func()Mocha chai 使用中间件 func() 在 it() 块中使用 expect() 挂起
【发布时间】:2016-02-19 07:33:42
【问题描述】:

我不知道为什么,但这会将成功返回为挂起,但失败的成功返回失败,使用 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

    }));
})

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

【问题讨论】:

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


    【解决方案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();
    
          })
       });
    })
    

    【讨论】:

    • 我最近浏览了mocha docs,我对有这个done() 功能大吃一惊,哈哈。无论如何,谢谢,我会接受你的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-06
    • 2019-09-06
    • 2015-11-03
    • 1970-01-01
    • 2019-02-15
    • 1970-01-01
    • 2014-06-09
    相关资源
    最近更新 更多