我有一个基于 TypeScript 的 Vue 项目,使用Jest作为测试框架。我在要测试的模块中有操作。
我的操作如下所示:
@Action({})
saveSomeData (payload: any): Promise<any> {
const { isActive, id, routes } = payload
return this.context.dispatch('otherModule/createId', '', { root: true })
.then((id: string) => {
payload = { isActive, id, routes, type: 'postRoutes' }
return this.context.dispatch('submitRoutes', payload)
})
}
@Action({})
submitRoutes (payload: any): Promise<any> {
const { isActive, id, routes, type } = payload
return ActiveService.setActive(id)
.then(() => this.context.dispatch(type, { id, routes }))
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试的样子:
// Mocking createId in otherModule module to …Run Code Online (Sandbox Code Playgroud)