diff --git a/api/test.md b/api/test.md index b0fc69ff..bd3c9fa2 100644 --- a/api/test.md +++ b/api/test.md @@ -249,6 +249,31 @@ test('add item', ({ todos }) => { }) ``` +## test.scoped 3.1.0 {#test-scoped} + +- **Alias:** `it.scoped` + +Use `test.scoped` to override fixture values for all tests within the current suite and its nested suites. This must be called at the top level of a `describe` block. See [Scoping Values to Suite](/guide/test-context.html#scoping-values-to-suite) for more information. + +```ts +import { test as baseTest, describe, expect } from 'vitest' + +const test = baseTest.extend({ + dependency: 'default', + dependant: ({ dependency }, use) => use({ dependency }), +}) + +describe('use scoped values', () => { + test.scoped({ dependency: 'new' }) + + test('uses scoped value', ({ dependant }) => { + // `dependant` uses the new overridden value that is scoped + // to all tests in this suite + expect(dependant).toEqual({ dependency: 'new' }) + }) +}) +``` + ## test.skip - **Alias:** `it.skip` diff --git a/guide/test-tags.md b/guide/test-tags.md index 1f871d4b..6e16f268 100644 --- a/guide/test-tags.md +++ b/guide/test-tags.md @@ -3,11 +3,9 @@ title: Test Tags | Guide outline: deep --- - +# Test Tags 4.1.0 {#test-tags} -# Test Tags 4.1.0 - -[`Tags`](/config/tags) allow you to mark tests and change their options based on the tag's definition. +[`Tags`](/config/tags) let you label tests so you can filter what runs and override their options when needed. ## Defining Tags