You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Each fixture can access previously defined fixtures via its first parameter. This works for both function and non-function fixtures:
@@ -507,15 +499,13 @@ Note that you cannot override non-test fixtures inside `describe` blocks:
507
499
508
500
```ts
509
501
test.describe('a nested suite', () => {
510
-
test.override('port', 3000) // throws an error
502
+
test.override('port', { scope: 'worker' }, 3000) // throws an error
511
503
})
512
504
```
513
505
514
506
Consider overriding it on the top level of the module, or by using [`injected`](#default-fixture-injected) option and providing the value in the project config.
515
507
516
508
Also note that in [non-isolate](/config/isolate) mode overriding a `worker` fixture will affect the fixture value in all test files running after it was overriden.
517
-
518
-
<!-- TODO(v5) should this be addressed? force a new worker if worker fixture is overriden? -->
519
509
:::
520
510
521
511
#### Test Scope (Default)
@@ -833,7 +823,7 @@ Note that you cannot introduce new fixtures inside `test.override`. Extend the t
833
823
834
824
### Type-Safe Hooks
835
825
836
-
When using `test.extend`, the extended `test` object provides type-safe `beforeEach` and `afterEach`hooks that are aware of the new context:
826
+
When using `test.extend`, the extended `test` object provides type-safe hooks that are aware of the extended context:
#### Suite-Level Hooks with Fixtures <Version>4.1.0</Version> {#suite-level-hooks}
843
+
844
+
The extended `test` object also provides [`beforeAll`](/api/hooks#beforeall), [`afterAll`](/api/hooks#afterall), and [`aroundAll`](/api/hooks#aroundall) hooks that can access file-scoped and worker-scoped fixtures:
Suite-level hooks (`beforeAll`, `afterAll`, `aroundAll`) **must be called on the `test` object returned from `test.extend()`** to have access to the extended fixtures. Using the global `beforeAll`/`afterAll`/`aroundAll` functions will not have access to your custom fixtures:
// ❌ WRONG: Global beforeAll doesn't have access to 'database'
883
+
beforeAll(({ database }) => {
884
+
// Error: 'database' is undefined
885
+
})
886
+
887
+
// ✅ CORRECT: Use test.beforeAll to access fixtures
888
+
test.beforeAll(({ database }) => {
889
+
// 'database' is available
890
+
})
891
+
```
892
+
893
+
This applies to all suite-level hooks: `beforeAll`, `afterAll`, and `aroundAll`.
894
+
:::
895
+
896
+
::: tip
897
+
Suite-level hooks can only access [**file-scoped** and **worker-scoped** fixtures](#fixture-scopes). Test-scoped fixtures are not available in these hooks because they run outside the context of individual tests. If you try to access a test-scoped fixture in a suite-level hook, Vitest will throw an error.
0 commit comments