Skip to content

Commit 546b24e

Browse files
authored
Use globals setting (#1501)
I've been starting a new project and follow this docs. Here's some suggestion: Since vitest-dev/vitest#565, `global` is deprecated. I propose a section to add a config for TypeScript.
1 parent 7b3a5a3 commit 546b24e

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/guide/scaling-up/testing.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,28 @@ export default defineConfig({
144144
// ...
145145
test: {
146146
// enable jest-like global test APIs
147-
global: true,
147+
globals: true,
148148
// simulate DOM with happy-dom
149149
// (requires installing happy-dom as a peer dependency)
150150
environment: 'happy-dom'
151151
}
152152
})
153153
```
154154

155+
:::tip
156+
If you are using TypeScript, add `vitest/globals` to the `types` field in your `tsconfig.json`.
157+
158+
```json
159+
// tsconfig.json
160+
161+
{
162+
"compileroptions": {
163+
"types": ["vitest/globals"]
164+
}
165+
}
166+
```
167+
:::
168+
155169
Then create a file ending in `*.test.js` in your project. You can place all test files in a test directory in project root, or in test directories next to your source files. Vitest will automatically search for them using the naming convention.
156170

157171
```js

0 commit comments

Comments
 (0)