Skip to content

Commit b9a032f

Browse files
authored
docs: add test.scoped to test api docs (#9524)
1 parent 490738d commit b9a032f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/api/test.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,31 @@ test('add item', ({ todos }) => {
247247
})
248248
```
249249

250+
## test.scoped <Version>3.1.0</Version> {#test-scoped}
251+
252+
- **Alias:** `it.scoped`
253+
254+
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.
255+
256+
```ts
257+
import { test as baseTest, describe, expect } from 'vitest'
258+
259+
const test = baseTest.extend({
260+
dependency: 'default',
261+
dependant: ({ dependency }, use) => use({ dependency }),
262+
})
263+
264+
describe('use scoped values', () => {
265+
test.scoped({ dependency: 'new' })
266+
267+
test('uses scoped value', ({ dependant }) => {
268+
// `dependant` uses the new overridden value that is scoped
269+
// to all tests in this suite
270+
expect(dependant).toEqual({ dependency: 'new' })
271+
})
272+
})
273+
```
274+
250275
## test.skip
251276

252277
- **Alias:** `it.skip`

0 commit comments

Comments
 (0)