我正在尝试编写以下测试:
return chai.assert.isRejected(quote.validate(), 'Amount is not valid number');
运行此测试时,它是成功的,但在对其进行捏造以确保它因以下内容而失败时,它仍然通过:
return chai.assert.isRejected(quote.validate(), '123Amount is not valid number');
我还尝试了以下方法:
return chai.assert.isRejected(quote.validate(), new Error('Amount is not valid number'));
但似乎失败了:
AssertionError: expected promise to be rejected with [Error: Amount is not valid number] but it was rejected with [Error: Amount is not valid number]
我有理由相信它失败了,因为它们引用了不同的错误实例,但不是 100% 确定。
理想情况下,我希望能够确保返回正确的错误/消息,但我似乎无法弄清楚并正在寻求一些帮助。
** 注意我也在使用 chai-as-promised
最佳答案
也许尝试使用expect而不是assert?我在尝试使用断言时遇到了同样的问题。
expect(promise).to.be.rejectedWith('错误消息。').and.notify(done)
关于node.js - chai.assert.isRejected 消息验证器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27410487/