TypeError: undefined is not an object (evaluating 'i18n._t')
背景今天写vue+element单元测试报了错ERROR LOG: '[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'i18n._t')"解决Unit tests not working since introducing vue-i18n大佬是这样回复的...
·
背景
今天写vue+element单元测试报了错
ERROR LOG: '[Vue warn]: Error in render: "TypeError: undefined is not an object (evaluating 'i18n._t')"
解决
Unit tests not working since introducing vue-i18n
大佬是这样回复的
You need to inject an i18n object when instantiating your component.
Using your example :
import Vue from 'vue'
import Home from '@/components/Home'
import VueI18n from 'vue-i18n'
Vue.use(VueI18n)
const i18n = new VueI18n({});
describe('Home.vue', () => {
it('should render correct contents', () => {
const Constructor = Vue.extend(Home)
const vm = new Constructor({i18n}).$mount()
expect(vm.$el.querySelector('h1').textContent)
.to.equal('Welcome to Server Client Project (STP)!')
})
})
加上去就好了
更多推荐
已为社区贡献35条内容
所有评论(0)