vue.js - Nuxt.js 中的 Jest 全局插件
问题描述
我正在尝试模拟一个在created()
jest 单元测试中的钩子上运行的插件,但是,我不断返回TypeError: this.$translations is not a function
,这导致我的所有测试都因该错误而失败:
文件内Component
:
created () {
this.$translations(this.page.translations)
}
文件内Test
:
import { translations } from '~/helpers/plugins/translations'
const localVue = createLocalVue()
localVue.use(translations)
const wrapper = shallowMount(TestComponent, {
localVue,
propsData
})
难道我做错了什么?
解决方案
我已经解决了这个问题,我要做的是mocks
用来模拟this.$translations()
作为一个函数:
const wrapper = shallowMount(TBase, {
localVue,
mocks: { $translations: () => {} },
propsData
})
推荐阅读
- python - 无法从 tensorflow 检查点读取以进行微调
- file-upload - Android QBCustomObject 文件上传资源未找到错误
- python - gcloud app deploy 在“运行 setup.py install for appscript”时失败
- jenkins - 我可以在 Jenkins Logstash 消息上设置“数据”属性吗?
- asynchronous - 还有比赛条件吗?
- c# - “文件名”不包含“_field”的定义,并且没有扩展方法“_field”接受类型的第一个参数
- c# - Visual Studio 和 Swagger/Swashbuckle - 部署具有 DateTimeOffset 的 WebAPI
- linux - 在脚本/签名文件处编译 Linux 内核 5.2.9 失败
- java - Spring Boot JPA 关系映射和连接查询
- sorting - 谷歌表格查询列表按行排序