fix: 完善单测demo;升级单测版本
This commit is contained in:
@@ -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(() => {})
|
||||
|
||||
Reference in New Issue
Block a user