Skip to content
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

[Feature] Expect.toPass to work with soft asserts #20437

Closed
denkorz opened this issue Jan 27, 2023 · 4 comments · Fixed by #20509
Closed

[Feature] Expect.toPass to work with soft asserts #20437

denkorz opened this issue Jan 27, 2023 · 4 comments · Fixed by #20509

Comments

@denkorz
Copy link

denkorz commented Jan 27, 2023

After some test actions, I load a complex object via API and check its structure by multiple soft asserts.
This structure doesn't update fast so the API call might return the object with obsolete data.
I tried wrapping these soft asserts like

await expect(async () => {
   const myObject = await getObjectViaApi();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   expect.soft(myObject).toHaveSomething();
   console.log(test.info().errors.count);
}).toPass();

But the test fails and the console output looks like
7
14
21
28
35
35
35
35
35

@denkorz
Copy link
Author

denkorz commented Jan 27, 2023

I fixed it by the following approach, but I'm not sure this is a fully safe way with no side-effects

 await expect(async () => {
      test.info().errors = [];
      test.info().status = 'passed';

// all my soft asserts

expect(test.info().errors).toHaveLength(0);
    }).toPass();

@pavelfeldman
Copy link
Member

I don't think we have a good definition of soft assert inside toPass block. One is saying "retry if failed" and another is saying "pretend you did not fail". Do you think you could remove soft? toPass will retry until all of the expects pass, so it does not seem to add much.

@denkorz
Copy link
Author

denkorz commented Jan 27, 2023

I don't think we have a good definition of soft assert inside toPass block. One is saying "retry if failed" and another is saying "pretend you did not fail". Do you think you could remove soft? toPass will retry until all of the expects pass, so it does not seem to add much.

The reason for soft assert is the same - make a test to be able to check multiple conditions. I have an object with inner objects. And some values with specific IDs in these inner objects should be changed after some test actions. So I verify every place and it's useful to use soft asserts instead of something like param1&&param2&&param3 as with soft asserts I can check several places and get an informative report in case of fail.
The same for toPass block - after test actions, the object updates in the background so there is no easy way to wait for it to be updated completely. So I use toPass block.

In your case if I use non-soft asserts and test fails, I see only the first issue.

@pavelfeldman
Copy link
Member

Why was this issue closed?

Thank you for your involvement. This issue was closed due to limited engagement (upvotes/activity), lack of recent activity, and insufficient actionability. To maintain a manageable database, we prioritize issues based on these factors.

If you disagree with this closure, please open a new issue and reference this one. More support or clarity on its necessity may prompt a review. Your understanding and cooperation are appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants