Exception for [no-wait-for-multiple-assertions] rule #595
-
Hi, I'm writing tests for a form component with validation (async). I need to assert two of my form fields show error messages and my assertions went like await waitFor(() => {
expect(scree.getByLabelText('Name')).toHaveErrorMessage('Name is required');
expect(scree.getByLabelText('Company')).toHaveErrorMessage('Company is required');
}); I feel it's totally fine to group these two assertions in a single |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @SevenOutman! I'm afraid that I don't see how we could add an exception to that. First, this rule makes sense for your use case too, since when the first error message appears, the second one should be there too, so you only need to await for one of them. This is on the same page as the scenario explained in the Common mistakes with React Testing Library post, so your test fails faster. In general, the
I guess your point is about asserting a mock is called once and is called with some args is connected somehow because you are asserting over the very same mock, but asserting a field has an error message, and another field has another error message is not related because they are different elements. But in terms of Nevertheless, if we find a reason to allow this behavior, I don't think it's doable. How would look like? I can't find a pattern to identify that use case, to be honest. |
Beta Was this translation helpful? Give feedback.
Hi @SevenOutman!
I'm afraid that I don't see how we could add an exception to that.
First, this rule makes sense for your use case too, since when the first error message appears, the second one should be there too, so you only need to await for one of them. This is on the same page as the scenario explained in the Common mistakes with React Testing Library post, so your test fails faster. In general, the
waitFor
util should look like this in your tests:I guess your point is about asserting a mock is called once and is cal…