fix: 完善单测demo;升级单测版本

This commit is contained in:
chenjinsong
2023-01-13 17:42:25 +08:00
parent 0f2fcbe9e6
commit 156979e79e
6 changed files with 61 additions and 13 deletions

View File

@@ -1,5 +1,3 @@
import 'jest-canvas-mock'
import axios from 'axios'
import { config } from '@vue/test-utils'
/* 开启测试 */
@@ -19,18 +17,19 @@ window.$dayJs = dayjs
/* 模拟vue-router库否则组件中引用vue-router的代码报错 */
jest.mock('vue-router', () => {
return {
useRouter: function () { return { currentRoute: '/' } },
useRoute: function () { return { query: {} } },
useRouter: jest.fn(),
useRoute: jest.fn(),
createWebHashHistory: jest.fn(),
createRouter: jest.fn().mockReturnValue({
beforeEach: jest.fn()
})
}
})
/* 模拟axios */
jest.mock('axios')
/* 模拟$t */
config.global.mocks.$t = key => key
/* 模拟$route具体用例中需要不同值时重写覆盖即可 */
config.global.mocks.$route = { query: '' }
/* 消除warn */
jest.spyOn(console, 'warn').mockImplementation(() => {})