provide
- Type:
Partial<ProvidedContext>
Define values that can be accessed inside your tests using inject method.
ts
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
provide: {
API_KEY: '123',
},
},
})ts
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:
ts
declare module 'vitest' {
export interface ProvidedContext {
API_KEY: string
}
}
// mark this file as a module so augmentation works correctly
export {}