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

docs: update snapshot section to provide details on how to use with concurrent test #2733

Merged
merged 6 commits into from
Feb 14, 2023

Conversation

asdfjkalsdfla
Copy link
Contributor

docs: update Snapshot section to provide details on how to use with concurrent test

close #2729

@@ -44,16 +44,16 @@ Learn more about [Test Filtering](./filtering.md).

## Running tests concurrently

Use `.concurrent` in consecutive tests to run them in parallel.
Use `.concurrent` in consecutive tests to run them in parallel. Also, be sure to use `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add ::warning section and mention snapshot testing there and expect.assertions. Otherwise, it doesn't matter what expect you use there.

@@ -149,13 +149,15 @@ You cannot use this syntax, when using Vitest as [type checker](/guide/testing-t
test.todo.concurrent(/* ... */) // or test.concurrent.todo(/* ... */)
```

When using Snapshots with async concurrent tests, due to the limitation of JavaScript, you need to use the `expect` from the [Test Context](/guide/test-context.md) to ensure the right test is being detected.
When using Snapshots with async concurrent tests, you need to use `expect` from the [Test Context](/guide/test-context.md) and call `expect.assertions` to ensure the test will detect any failures.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I did not mean that. You don't need to call expect.assertions in this case. You need to use local expect, if you are calling assertions in a concurrent test. This is also true for your other edits. We just need to mention that this API depends on the local expect in this case.

@sheremet-va
Copy link
Member

@dammy001 can you review this PR, please?

docs/guide/snapshot.md Outdated Show resolved Hide resolved
docs/guide/snapshot.md Outdated Show resolved Hide resolved
docs/api/expect.md Outdated Show resolved Hide resolved
remove extra spaces

Co-authored-by: Anjorin Damilare <damilareanjorin1@gmail.com>
@sheremet-va sheremet-va changed the title docs: update Snapshot section to provide details on how to use with concurrent test docs: update snapshot section to provide details on how to use with concurrent test Feb 14, 2023
@sheremet-va sheremet-va merged commit b67a5fb into vitest-dev:main Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Snapshot tests fail with concurrent execution (Error: Snapshot cannot be used outside of test)
3 participants