mirror of
https://github.com/vitest-dev/vitest.git
synced 2025-12-08 18:26:03 +00:00
1.1 KiB
1.1 KiB
| title | outline |
|---|---|
| provide | Config | deep |
provide
- Type:
Partial<ProvidedContext>
Define values that can be accessed inside your tests using inject method.
:::code-group
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
provide: {
API_KEY: '123',
},
},
})
import { expect, inject, test } from 'vitest'
test('api key is defined', () => {
expect(inject('API_KEY')).toBe('123')
})
:::
::: warning Properties have to be strings and values need to be serializable because this object will be transferred between different processes. :::
::: tip
If you are using TypeScript, you will need to augment ProvidedContext type for type safe access:
declare module 'vitest' {
export interface ProvidedContext {
API_KEY: string
}
}
// mark this file as a module so augmentation works correctly
export {}
:::