boolean
false
--globals, --no-globals, --globals=false
By default, vitest does not provide global APIs for explicitness. If you prefer to use the APIs globally like Jest, you can pass the --globals option to CLI or add globals: true in the config.
import { defineConfig } from 'vitest/config'
export default defineConfig({
test: {
globals: true,
},
})
Note that some libraries, e.g., @testing-library/react, rely on globals being present to perform auto cleanup.
To get TypeScript working with the global APIs, add vitest/globals to the types field in your tsconfig.json:
{
"compilerOptions": {
"types": ["vitest/globals"]
}
}
If you have redefined your typeRoots to include additional types in your compilation, you will need to add back the node_modules to make vitest/globals discoverable:
{
"compilerOptions": {
"typeRoots": ["./types", "./node_modules/@types", "./node_modules"],
"types": ["vitest/globals"]
}
}
© 2021-Present VoidZero Inc. and Vitest contributors
Licensed under the MIT License.
https://vitest.dev/config/globals