Vue.js Nuxt.js中的Jest全局插件
我试图模拟一个在jest单元测试中的Vue.js Nuxt.js中的Jest全局插件,vue.js,jestjs,nuxt.js,Vue.js,Jestjs,Nuxt.js,我试图模拟一个在jest单元测试中的created()钩子上运行的插件,但是,我不断返回TypeError:this.$translations不是一个函数,它会导致我的所有测试失败,并导致该错误: 在组件文件中: 已创建(){ 此.$translations(此.page.translations) } 在测试文件中: 从“~/helpers/plugins/translations”导入{translations} const localVue=createLocalVue() local
created()
钩子上运行的插件,但是,我不断返回TypeError:this.$translations不是一个函数,它会导致我的所有测试失败,并导致该错误:
在组件
文件中:
已创建(){
此.$translations(此.page.translations)
}
在测试
文件中:
从“~/helpers/plugins/translations”导入{translations}
const localVue=createLocalVue()
localVue.use(翻译)
const wrapper=shallowMount(TestComponent{
localVue,
普洛斯达
})
我做错什么了吗?我已经解决了这个问题,我要做的是使用mock
来模拟这个。$translations()
作为一个函数:
const wrapper = shallowMount(TBase, {
localVue,
mocks: { $translations: () => {} },
propsData
})