【问题标题】:Chai expect doesn't fail the test if it is inside a callback如果它在回调中,Chai 期望不会失败测试
【发布时间】:2021-02-19 13:36:33
【问题描述】:

所以无论我做什么,这个测试都不会失败。

it("should not save the user(duplicate user)", function (done) {
        const user = {
            name: "faruk",
            email: "faruk@farukmail.com",
            password: "faruk2356",
        };
        model.saveUser(user, function (err, doc) {
            expect(err).to.exist;
            done()
        });
    });

如果我在 Console.log 中显示此错误 AssertionError: expected null to exist。 所以有一个错误,但测试没有失败。并且错误甚至与保存用户功能无关,而是 chai 抛出的错误。当我 console.log(err) 它记录的不是错误回调给出的而是错误 chai 抛出时,这怎么可能呢?看不懂。

【问题讨论】:

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


    【解决方案1】:

    我也遇到过类似的问题,但那是因为我的大脑很顺畅,所以我将测试放在 describe() 而不是 it()。显然,您的问题与我的问题不同,因为您使用的是it(),但也许它仍然适用于其他人。希望这可以帮助我所有的脑筋急转弯的朋友。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-04
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 2020-08-27
      • 2016-02-23
      相关资源
      最近更新 更多