Jest learning manual
Docs
Samples
采坑系列
function fetchData() {
return new Promise(function(resolve, reject) {
if (true) {
resolve("peanut butter");
} else {
reject(new Error("error"));
}
});
}
test("the fetch fails with an error", async () => {
// await expect(fetchData()).rejects.toMatch("error");
//expect(received).rejects.toMatch()
// Expected received Promise to reject, instead it resolved to value "peanut butter"
// await expect(fetchData()).rejects.toThrow("error");
// expect(received).rejects.toThrow()
// Expected received Promise to reject, instead it resolved to value "peanut butter"
});最后更新于