-
-
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
removed useless expect.assertions #7131
Conversation
In a lot of case `expect.assertions(1);` is no need. It can be confusing.
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
I think this is intentional, from those same docs:
|
@rickhanlonii exactly ! So why should we use |
So I looked a little closer and this change is great - expect.assertions is not needed when using resolves/rejects 👍 To explain a little better and answer your question - when you're using resolves/rejects, we have built in checking for unexpected behavior. So let's say you have this test: const fetchData = () => Promise.resolve('foo');
test('the fetch fails with an error', () => {
return expect(fetchData()).rejects.toMatch('error');
}); Then we show this error: So we tell you that you're expecting it to reject, but it resolved. Where you need the expect.assertions is when you do your own promise handling, as in the other examples: const fetchData = () => Promise.resolve('foo');
test('the fetch fails with an error', () => {
expect.assertions(1);
return fetchData().catch(e => {
expect(e).toMatch('error')
});
}); Here without the |
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.
LGTM
This needs a changelog entry and it can go |
Thanks @Flavien-Pensato for your first Jest contribution! |
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. |
In a lot of case
expect.assertions(1);
is no need. It can be confusing.In fact, we should never use
expect.assertions
^^ expect in some case explained by @rickhanlonii .