【发布时间】:2019-06-26 03:19:30
【问题描述】:
如果我尝试运行下面的东西(使用yarn run jest),我会得到 TypeError: _vm.$t is not a function,因为SearchField 正在使用翻译("$t('search')" )。
import { mount } from "@vue/test-utils";
import SearchField from "@/components/ui/SearchField";
describe("SearchField", () => {
const wrapper = mount(SearchField);
it("renders correctly", () => {
expect(wrapper.element).toMatchSnapshot();
});
});
如果我在开头添加以下三行,我会得到 TypeError: Cannot read property '_t' of undefined。
import Vue from "vue";
import VueI18n from "vue-i18n";
Vue.use(VueI18n);
【问题讨论】:
-
你应该为
$t提供模拟 - 类似mount(SearchField, { mocks: { $t: () => {} }. })
标签: vue.js jestjs nuxt.js nuxt-i18n