-
-
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
feat: fail tests when multiple done()
calls are made
#10624
Conversation
done()
calls are founddone()
calls are found
done()
calls are founddone()
calls are made
@flozender just noticed this in the OP - it's perfectly fine to just change |
packages/jest-circus/src/utils.ts
Outdated
@@ -212,6 +216,15 @@ export const callAsyncCircusFn = ( | |||
|
|||
return reason ? reject(errorAsErrorObject) : resolve(); | |||
}); | |||
|
|||
if (testOrHook.seenDone) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do it down here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to first check if done
was passed with a reason
for failure, if so, return the reason
. Or else, we can check if done
was called more than once and return that as an error. We have some tests that checked if reason
was being sent out properly, and they were failing because we returned our Expected done to be called once, but it was called multiple times.
error before the reason was checked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which tests are those? If they call done
multiple times that's wrong. I can take a look if there are cases it does make sense though - could you point me to the tests that failed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's one such test that calls done
more than once. EDIT: let me just check if my latest commit is causing the CI to fail and I'm just confused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I was confused about something else, please ignore this. I'll revert the position-change commit. However, this doesn't work as expected: https://github.com/facebook/jest/blob/3641e3cc7309caf4c755add40bebcb77fc18b786/e2e/failures/__tests__/errorAfterTestComplete.test.js#L10-L13
Expects: Error: Caught error after test environment was torn down
Receives: Expected done to be called once, but it was called multiple times.
(Same error as in the CI)
UPD: So turns out I was trying to fix this issue by moving the seenDone
check to after checking if the environment was torn down, hence the movement of the check. But clearly, that didn't work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll merge this when we're ready to land breaking changes 🙂
@flozender CI is unhappy here - would you be able to take a look? |
Sure, I'll try to fix it. |
@SimenB I get an error here: https://github.com/facebook/jest/blob/a028bc13b8cb7d9f10933da67a41e7f52db277dd/packages/jest-jasmine2/src/jasmine/Env.ts#L56 Looks like it's a new change, what should I do here? |
@flozender have you run |
That didn't seem to work. I ran |
Very odd. You can try to delete |
Perfect, that worked! |
Also please add a test like test('something', done => {
Promise.resolve().then(() => {
done();
done();
});
}); |
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
Thanks for a great contribution @flozender! |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
Aims to close #7052.
When
done()
is called more than once, the test is reported as a failure.Changes made only to
jest-circus
as of now.Test plan
e2e tests added to emulate the issue.