admin管理员组文章数量:1405544
I am setting up some asynchronous junit
typescript tests and it seems I don't understand the documentation correctly.
I wrote a test asking a web API for a specific svg image by sending the ID of the image.
The test sends no ID so the web API should return http code 404. This the test and it works well:
test("getSvgByImageId unknown", () => {
expect.assertions(1);
return client.getSvgImageById("")
.then(svg => {
fail("API should return error")
})
.catch(error => {
expect(error.status).toBe(404);
})
});
But why should I use the expect.assertions(x) when I use the fail() method? The test also works without the expect.assertions(x) line.
I am setting up some asynchronous junit
typescript tests and it seems I don't understand the documentation correctly.
I wrote a test asking a web API for a specific svg image by sending the ID of the image.
The test sends no ID so the web API should return http code 404. This the test and it works well:
test("getSvgByImageId unknown", () => {
expect.assertions(1);
return client.getSvgImageById("")
.then(svg => {
fail("API should return error")
})
.catch(error => {
expect(error.status).toBe(404);
})
});
But why should I use the expect.assertions(x) when I use the fail() method? The test also works without the expect.assertions(x) line.
Share Improve this question edited Jan 18, 2019 at 9:14 skyboyer 23.8k7 gold badges62 silver badges71 bronze badges asked Jan 17, 2019 at 6:50 FleMoFleMo 5651 gold badge6 silver badges21 bronze badges 1- 1 Two documentation pages really helped me: jestjs.io/docs/en/asynchronous and jestjs.io/docs/en/tutorial-async – Sixty4Bit Commented Mar 2, 2021 at 20:40
1 Answer
Reset to default 7From this post by a Jest
collaborator in reference to the global fail()
function:
That will stop working at some point - it's not part of Jest's documented API.
Jest
is based on Jasmine
and fail()
is a carryover from Jasmine
.
It is not officially part of the Jest
documentation so it should not be used as it could be removed from future Jest
releases.
本文标签: javascriptUsing expectassertions(x) vs using fail() in jest testsStack Overflow
版权声明:本文标题:javascript - Using expect.assertions(x) vs using fail() in jest tests - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744318702a2600388.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论