-
Notifications
You must be signed in to change notification settings - Fork 1
2、集成到现有Vue项目
SamYan edited this page May 10, 2018
·
1 revision
1、jest:^22.2.2
2、babel-jest:^22.2.2
3、vue-jest:^2.1.0
4、@vue/test-utils:^1.0.0-beta.11
5、babel-plugin-istanbul:^4.1.5
npm install --save-dev jest babel-jest vue-jest @vue/test-utils babel-plugin-istanbul
"scripts": {
"test": "jest"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest",
"^.+\\.(js)$": "<rootDir>/node_modules/babel-jest"
},
"moduleNameMapper": {
"^~/(.*)$": "<rootDir>/$1"
}
}
{
"env": {
"test": {
"presets": ["env", "stage-2"],
"plugins": ["istanbul"]
}
}
}
function helloWorld () {
return 'Hello World'
}
describe('hello world', () => {
it('should render correct result', () => {
expect(helloWorld()).toEqual('Hello World')
})
})
打开命令窗口,输入如下指令
npm run test
结果如上图所示,表明已成功将Jest集成到现有项目中,真是可喜可贺^_^