init
parent
dd37f247f8
commit
678b5832f7
14
.babelrc
14
.babelrc
|
@ -8,5 +8,17 @@
|
|||
}],
|
||||
"stage-2"
|
||||
],
|
||||
"plugins":["transform-vue-jsx", "transform-runtime"]
|
||||
"plugins": ["transform-vue-jsx", "transform-runtime"],
|
||||
"env": {
|
||||
"test": {
|
||||
"presets": [
|
||||
["env", {
|
||||
"targets": {
|
||||
"node": "current"
|
||||
}
|
||||
}]
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ module.exports = {
|
|||
browser: true,
|
||||
node: true,
|
||||
es6: true,
|
||||
jest: true
|
||||
},
|
||||
extends: 'eslint:recommended',
|
||||
// required to lint *.vue files
|
||||
|
|
|
@ -5,6 +5,7 @@ npm-debug.log*
|
|||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
package-lock.json
|
||||
tests/coverage/
|
||||
|
||||
# Editor directories and files
|
||||
.idea
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
module.exports = {
|
||||
verbose: true,
|
||||
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
|
||||
transform: {
|
||||
'^.+\\.vue$': 'vue-jest',
|
||||
'^.+\\.jsx?$': 'babel-jest'
|
||||
},
|
||||
moduleNameMapper: {
|
||||
'^@/(.*)$': '<rootDir>/src/$1'
|
||||
},
|
||||
snapshotSerializers: ['jest-serializer-vue'],
|
||||
testMatch: [
|
||||
'<rootDir>/(tests/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx))'
|
||||
],
|
||||
// collectCoverageFrom: ['src/utils/**/*.{js,vue}'],
|
||||
'coverageDirectory': './tests/coverage',
|
||||
// 'collectCoverage': true,
|
||||
'coverageReporters': [
|
||||
'lcov',
|
||||
'text-summary'
|
||||
]
|
||||
}
|
|
@ -10,7 +10,7 @@
|
|||
"build": "node build/build.js",
|
||||
"build:report": "npm_config_report=true node build/build.js",
|
||||
"lint": "eslint --ext .js,.vue src",
|
||||
"test": "npm run lint"
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "0.17.1",
|
||||
|
@ -23,10 +23,12 @@
|
|||
"vuex": "3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vue/test-utils": "^1.0.0-beta.20",
|
||||
"autoprefixer": "7.2.3",
|
||||
"babel-core": "6.26.0",
|
||||
"babel-eslint": "8.0.3",
|
||||
"babel-helper-vue-jsx-merge-props": "2.0.3",
|
||||
"babel-jest": "^23.4.0",
|
||||
"babel-loader": "7.1.2",
|
||||
"babel-plugin-syntax-jsx": "6.18.0",
|
||||
"babel-plugin-transform-runtime": "6.23.0",
|
||||
|
@ -45,6 +47,8 @@
|
|||
"file-loader": "1.1.5",
|
||||
"friendly-errors-webpack-plugin": "1.6.1",
|
||||
"html-webpack-plugin": "2.30.1",
|
||||
"jest": "^23.4.0",
|
||||
"jest-serializer-vue": "^2.0.2",
|
||||
"node-notifier": "5.1.2",
|
||||
"node-sass": "^4.7.2",
|
||||
"optimize-css-assets-webpack-plugin": "3.2.0",
|
||||
|
@ -61,6 +65,7 @@
|
|||
"uglifyjs-webpack-plugin": "1.1.3",
|
||||
"url-loader": "0.6.2",
|
||||
"vue-loader": "13.7.2",
|
||||
"vue-jest": "^2.6.0",
|
||||
"vue-style-loader": "3.0.3",
|
||||
"vue-template-compiler": "2.5.10",
|
||||
"webpack": "3.10.0",
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
<template>
|
||||
<div>
|
||||
<h1>Count: {{ counter }}</h1>
|
||||
|
||||
<button @click="counter++" jest="increment-button">+1</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
counter: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -19,10 +19,11 @@ export default {
|
|||
isActive: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
toggleClick: {
|
||||
type: Function,
|
||||
default: null
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggleClick() {
|
||||
this.$emit('toggleClick')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<template>
|
||||
<el-menu class="navbar" mode="horizontal">
|
||||
<hamburger class="hamburger-container" :toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
|
||||
<hamburger class="hamburger-container" @toggleClick="toggleSideBar" :isActive="sidebar.opened"></hamburger>
|
||||
<breadcrumb></breadcrumb>
|
||||
<el-dropdown class="avatar-container" trigger="click">
|
||||
<div class="avatar-wrapper">
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
// import { shallowMount } from '@vue/test-utils'
|
||||
// import Breadcrumb from '@/components/Breadcrumb.vue'
|
||||
|
||||
// describe('Breadcrumb.vue', () => {
|
||||
// const wrapper = shallowMount(Breadcrumb)
|
||||
|
||||
// it('toggle', () => {
|
||||
// expect(wrapper.vm.counter).toBe(0)
|
||||
// wrapper.find('[jest="increment-button"]').trigger('click')
|
||||
// expect(wrapper.vm.counter).toBe(1)
|
||||
// })
|
||||
|
||||
// // it('渲染正确', () => {
|
||||
// // expect(wrapper.html()).toContain('<span class="count">0</span>')
|
||||
// // })
|
||||
|
||||
// it('是一个按钮', () => {
|
||||
// expect(wrapper.contains('button')).toBe(true)
|
||||
// })
|
||||
|
||||
// // it('snapshot test', () => {
|
||||
// // expect(wrapper.element).toMatchSnapshot()
|
||||
// // })
|
||||
// })
|
|
@ -0,0 +1,24 @@
|
|||
import { shallowMount } from '@vue/test-utils'
|
||||
import Counter from '@/components/Counter.vue'
|
||||
|
||||
describe('test Counter.vue', () => {
|
||||
const wrapper = shallowMount(Counter)
|
||||
|
||||
it('increments counter', () => {
|
||||
expect(wrapper.vm.counter).toBe(0)
|
||||
wrapper.find('[jest="increment-button"]').trigger('click')
|
||||
expect(wrapper.vm.counter).toBe(1)
|
||||
})
|
||||
|
||||
// it('渲染正确', () => {
|
||||
// expect(wrapper.html()).toContain('<span class="count">0</span>')
|
||||
// })
|
||||
|
||||
it('是一个按钮', () => {
|
||||
expect(wrapper.contains('button')).toBe(true)
|
||||
})
|
||||
|
||||
// it('snapshot test', () => {
|
||||
// expect(wrapper.element).toMatchSnapshot()
|
||||
// })
|
||||
})
|
|
@ -0,0 +1,27 @@
|
|||
import { shallowMount } from '@vue/test-utils'
|
||||
import Hamburger from '@/components/Hamburger/index.vue'
|
||||
|
||||
describe('Hamburger.vue', () => {
|
||||
it('toggle click', () => {
|
||||
const wrapper = shallowMount(Hamburger)
|
||||
|
||||
const mockFn = jest.fn()
|
||||
wrapper.vm.$on('toggleClick', mockFn)
|
||||
|
||||
// 触发按钮的点击事件
|
||||
wrapper.find('.hamburger').trigger('click')
|
||||
expect(mockFn).toBeCalled()
|
||||
})
|
||||
|
||||
// it('渲染正确', () => {
|
||||
// expect(wrapper.html()).toContain('<span class="count">0</span>')
|
||||
// })
|
||||
|
||||
// it('是一个按钮', () => {
|
||||
// expect(wrapper.contains('button')).toBe(true)
|
||||
// })
|
||||
|
||||
// it('snapshot test', () => {
|
||||
// expect(wrapper.element).toMatchSnapshot()
|
||||
// })
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
function sum(a = 1, b = 1) {
|
||||
return a + b
|
||||
}
|
||||
module.exports = sum
|
|
@ -0,0 +1,6 @@
|
|||
import sum from './sum'
|
||||
|
||||
test('adds 1 + 2 to equal 3', () => {
|
||||
expect(sum(1, 2)).toBe(3)
|
||||
})
|
||||
|
Loading…
Reference in New Issue