From fa41cd45df8502d720e714e2046ed9ac8c1e50e1 Mon Sep 17 00:00:00 2001 From: Tom Thumb <74577069+asdfjkalsdfla@users.noreply.github.com> Date: Sat, 4 Feb 2023 12:18:49 -0500 Subject: [PATCH] Add ref to expect.assertions --- docs/api/index.md | 4 +++- docs/guide/features.md | 6 +++++- docs/guide/snapshot.md | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/docs/api/index.md b/docs/api/index.md index b593c87381ca..a31964ac8e18 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -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. ```ts test.concurrent('test 1', async ({ expect }) => { + expert.assertions(1) expect(foo).toMatchSnapshot() }) test.concurrent('test 2', async ({ expect }) => { + expert.assertions(1) expect(foo).toMatchSnapshot() }) ``` diff --git a/docs/guide/features.md b/docs/guide/features.md index c0b17333e88b..4c4a5059da49 100644 --- a/docs/guide/features.md +++ b/docs/guide/features.md @@ -44,7 +44,7 @@ Learn more about [Test Filtering](./filtering.md). ## Running tests concurrently -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. +Use `.concurrent` in consecutive tests to run them in parallel. ```ts import { describe, it } from 'vitest' @@ -72,6 +72,10 @@ describe.concurrent('suite', () => { You can also use `.skip`, `.only`, and `.todo` with concurrent suites and tests. Read more in the [API Reference](../api/#test-concurrent). +::: warning +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. +::: + ## Snapshot [Jest-compatible](https://jestjs.io/docs/snapshot-testing) snapshot support. diff --git a/docs/guide/snapshot.md b/docs/guide/snapshot.md index 2c54cf990aa0..7b52f5eab67b 100644 --- a/docs/guide/snapshot.md +++ b/docs/guide/snapshot.md @@ -34,7 +34,7 @@ exports['toUpperCase 1'] = '"FOOBAR"' The snapshot artifact should be committed alongside code changes, and reviewed as part of your code review process. On subsequent test runs, Vitest will compare the rendered output with the previous snapshot. If they match, the test will pass. If they don't match, either the test runner found a bug in your code that should be fixed, or the implementation has changed and the snapshot needs to be updated. ::: warning -When using Snapshots with async concurrent tests, you need to use `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. ::: ## Inline Snapshots @@ -64,7 +64,7 @@ it('toUpperCase', () => { This allows you to see the expected output directly without jumping across different files. ::: warning -When using Snapshots with async concurrent tests, you need to use `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. ::: ## Updating Snapshots