jest for typescript in vscode
add dependencies
typescript has included some deps, install deps below
ts-nodets-jest
add config file
ts-jest support .ts config, just add file jest.config.ts to project root dir.
u have to told jest to use ts-jest to compile before runing, so config {preset: 'ts-jest'}.
the content like:
1 | import type { Config } from '@jest/types'; |
test
u can just run:
1 | npm jest |
by default, it will run all *.test.ts files which in <root_dir>/test
see more ts-jest config options at https://kulshekhar.github.io/ts-jest/docs/
test single file
in common, we don’t want run all test files.
u can add filename after command ‘jest’
1 | npm jest filename_with_extension |
see more jest command options at https://jestjs.io/docs/cli
config vscode to run jest in debug view
add configurations in .vscode/launch.json
jestcurrent opened file1
2
3
4
5
6
7
8
9
10
11
12
13
14
15{
"type": "node",
"request": "launch",
"name": "Jest Current File",
"program": "${workspaceFolder}/node_modules/.bin/jest",
"args": [
"${fileBasenameNoExtension}",
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"disableOptimisticBPs": true,
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
}
}jestall files
remove prop:args above, see jest cli docs and vscode launch debug
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 AlMirai!