File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ # vue-test-utils-typescript-example
2+
3+ > Example project using TypeScript, Jest + vue-test-utils together
4+
5+ This is based on the ` vue-cli ` 3 ` basic ` template. Test-specific changes include:
6+
7+ ### Additional Dependencies
8+
9+ - ` vue-test-utils `
10+ - ` jest `
11+ - ` ts-jest ` (for TypeScript compilation in tests)
12+ - ` vue-jest ` (for handling ` *.vue ` files in tests)
13+ - ` jest-serializer-vue ` (for snapshot tests)
14+
15+ ### Additional Configuration
16+
17+ #### ` package.json `
18+
19+ The following configurations are recommended for Jest:
20+
21+ ``` js
22+ {
23+ " jest" : {
24+ " moduleFileExtensions" : [
25+ " js" ,
26+ " json" ,
27+ " ts" ,
28+ // tell Jest to handle *.vue files
29+ " vue"
30+ ],
31+ " transform" : {
32+ // process TypeScript files
33+ " ^.+\\ .ts$" : " ts-jest" ,
34+ // process *.vue files with vue-jest
35+ " .*\\ .(vue)$" : " vue-jest"
36+ },
37+ // support the same @ -> src alias mapping in source code
38+ " moduleNameMapper" : {
39+ " ^@/(.*)$" : " <rootDir>/src/$1"
40+ },
41+ // serializer for snapshots
42+ " snapshotSerializers" : [
43+ " jest-serializer-vue"
44+ ]
45+ }
46+ }
47+ ```
48+
49+ ### Build Commands
50+
51+ ``` bash
52+ # install dependencies
53+ npm install
54+
55+ # serve with hot reload at localhost:8080
56+ npm run dev
57+
58+ # build for production with minification
59+ npm run build
60+
61+ # run tests
62+ npm test
63+ ```
Original file line number Diff line number Diff line change 66 "serve" : " vue-cli-service serve" ,
77 "build" : " vue-cli-service build" ,
88 "lint" : " vue-cli-service lint" ,
9+ "test" : " npm run test:unit" ,
910 "test:unit" : " jest"
1011 },
1112 "dependencies" : {
You can’t perform that action at this time.
0 commit comments