feat: 增加单元测试功能

This commit is contained in:
chenj
2022-12-06 17:01:46 +08:00
parent 1154ec3099
commit 0ffe414725
7 changed files with 105 additions and 51 deletions

28
src/Test.vue Normal file
View File

@@ -0,0 +1,28 @@
<template>
<span data-test="count">{{count}}</span>
<button data-test="button" @click="click">click</button>
</template>
<script>
/* vue-jest的测试示例 */
import VueRouter from 'vue-router'
export default {
name: 'Test',
data () {
return {
count: 0
}
},
methods: {
click () {
this.count++
}
},
created () {
const { currentRoute } = VueRouter.useRouter()
return {
currentRoute
}
}
}
</script>

View File

@@ -1,37 +0,0 @@
module.exports = {
globals: {
// work around: https://github.com/kulshekhar/ts-jest/issues/748#issuecomment-423528659
'ts-jest': {
diagnostics: {
ignoreCodes: [151001]
}
}
},
testEnvironment: 'jsdom',
transform: {
'^.+\\.vue$': 'vue-jest',
'^.+\\.(t|j)sx?$': [
'babel-jest', {
presets: [
[
'@babel/preset-env',
{
targets: {
node: true
}
}
],
'@babel/preset-typescript'
],
plugins: [
'@vue/babel-plugin-jsx',
'@babel/plugin-proposal-class-properties'
]
}
]
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
// u can change this option to a more specific folder for test single component or util when dev
// for example, ['<rootDir>/packages/input']
roots: ['<rootDir>']
}

View File

@@ -31,10 +31,6 @@ const routes = [
path: '/detection/:typeName',
component: () => import('@/views/detections/Index')
},
{
path: '/temp',
component: () => import('@/views/Temp')
},
{
path: '/businessLog/viewer',
component: () => import('@/views/businessLog/Viewer')

View File

@@ -1,9 +0,0 @@
<template>
<div>Temp</div>
</template>
<script>
export default {
name: 'Temp'
}
</script>