[Vuejs]-Error in render: "TypeError: Cannot read property '_t' of undefined" in Unit Test with Jest

0👍

Going through Github issues discussing that very error, I found this magic comment by cesalberca:

"This works as long as it’s shallow. If you mount the component and any
subcomponent uses translations the tests will fail […]"

I replaced mount by shallowMount and now the error is gone:

// const wrapper = mount(Foo, { localVue, mocks: { $t: () => {} } }) as any;

const wrapper = shallowMount(Foo, { localVue, mocks: { $t: () => {} } }) as any;

Leave a comment