Skip to content
This repository was archived by the owner on Nov 16, 2023. It is now read-only.

Commit 915cfab

Browse files
author
cho0o0
committed
add initial unit test code
1 parent c243b11 commit 915cfab

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

package.json

+30-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"main": "index.js",
77
"scripts": {
88
"build": "webpack",
9-
"test": "echo \"Error: no test specified\" && exit 1"
9+
"test": "jest"
1010
},
1111
"keywords": [],
1212
"author": {
@@ -21,11 +21,40 @@
2121
"vue-router": "^3.0.1"
2222
},
2323
"devDependencies": {
24+
"@types/jest": "^23.3.2",
25+
"@vue/test-utils": "^1.0.0-beta.25",
2426
"css-loader": "^0.28.1",
27+
"jest": "^23.6.0",
28+
"ts-jest": "^23.10.3",
2529
"ts-loader": "^2.0.3",
2630
"typescript": "^2.7.2",
31+
"vue-jest": "^2.6.0",
2732
"vue-loader": "^12.0.3",
2833
"vue-template-compiler": "^2.5.2",
2934
"webpack": "^2.5.0"
35+
},
36+
"jest": {
37+
"moduleFileExtensions": [
38+
"js",
39+
"ts",
40+
"vue"
41+
],
42+
"modulePaths": [
43+
"<rootDir>/src",
44+
"<rootDir>/node_modules"
45+
],
46+
"transform": {
47+
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
48+
".*\\.(ts)$": "ts-jest"
49+
},
50+
"moduleNameMapper": {
51+
"^@/(.*)$": "<rootDir>/src/$1"
52+
},
53+
"globals": {
54+
"vue-jest": {
55+
"tsConfigFile": "tsconfig.json"
56+
}
57+
},
58+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$"
3059
}
3160
}

src/components/Hello.spec.ts

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import Hello from '@/components/Hello.vue';
2+
import { mount } from '@vue/test-utils';
3+
4+
describe('Hello.vue', () => {
5+
it('should render', () => {
6+
const name = 'World';
7+
const initialEnthusiasm = 5;
8+
9+
const wrapper = mount(Hello, {
10+
propsData: {
11+
name, initialEnthusiasm
12+
}
13+
})
14+
expect(wrapper.find('.greeting').text()).toBe('Hello World!!!!!')
15+
})
16+
});

0 commit comments

Comments
 (0)