-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Jest reports a wrong test to have failed due to an exception #11869
Comments
You need to tell Jest to wait for the async work, otherwise it has no way of knowing which test is running when it fails. diff --git i/network.test.js w/network.test.js
index 2b0c1a4..908166b 100644
--- i/network.test.js
+++ w/network.test.js
@@ -4,7 +4,7 @@ const sleep = require("sleep-promise");
const Test =
{
doRequest() {
- axios.get('http://example.com')
+ return axios.get('http://example.com')
},
}
@@ -12,7 +12,7 @@ describe('a failing test', function () {
it('should do a request which fails when no network', async function () {
let requestSpy = jest.spyOn(Test, "doRequest")
- Test.doRequest();
+ await Test.doRequest();
// passes in any case
expect(requestSpy).toBeCalledTimes(1)
}); |
I am afraid this example was not the best to bring up the problem. |
You need to tell jest to wait some way or the other from within the test, otherwise the test will complete and your code keep running. You might need to restructure your code if that's not possible |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Version
27.2.0
Steps to reproduce
npm i
npm test
with network connection: they will all passnpm test
without network connection.Expected behavior
Jest should report that the test with the name
should do a request which fails when no network
failed, or if not backtraceable, an async test has failed at some pointActual behavior
Jest reports that
should do something else
failedAdditional context
No response
Environment
The text was updated successfully, but these errors were encountered: