【发布时间】:2020-07-03 14:03:54
【问题描述】:
这是this question的后续问题:
我不仅要测试函数是否抛出错误,还要测试抛出的错误是否具有相同的错误消息。 所以我尝试了:
expect(Person.getPerson.bind(Person, id)).to.throw(new Error(`Person ${id} not found`));
在 getPerson 函数内部会抛出一个错误,如下所示:
if (!isPersonExistent(id)) {
throw new Error(`Person ${id} not found`);
}
给定的消息如下所示:
AssertionError: expected [Function: bound getPerson] to throw 'Error: Person 1 not found' but 'Error: Person 1 not found' was thrown
我想这与两个错误对象是两个不同的对象有关。但是我如何也测试他们是否有相同的错误信息。最好一步完成。
【问题讨论】:
标签: typescript testing mocha.js chai