docs/config/provide.md
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 {}
:::