【发布时间】:2021-05-19 18:42:15
【问题描述】:
我正在测试一个带有部分随机输入的函数。无论如何,随机化的输入对象片段应该可以工作,但是如果我碰巧遇到一个失败的案例,我想通过在我的失败消息中包含无效输入来了解它是什么。
如何让 Jest 显示超出 expect 内容的失败消息?
这是我的代码:
describe("my module", () => {
it("should pass with some randomized inputs", () => {
const partialRandomInput = {
name: "Hardcoded",
age: Math.random() * 100,
yearsOfExperience: Math.random() * 30
};
const actualOutput = myModule(partialRandomInput);
expect(actualOutput).toEqual(false); // If this fails I only see the expect comparison that happened, which may not be helpful
});
});
也许在我上面的代码中,唯一的失败是如果随机 age 小于 5 并且随机 yearsOfExperience 小于 10。我想看看这些值当我的测试失败时用于partialRandomInput。
【问题讨论】:
标签: jestjs