相关疑难解决方法(0)

在 JEST 中嘲笑 i18n 的 useTranslation 不起作用

我的 React 组件使用 i18next 的翻译,我正在尝试使用 JEST 为其创建测试。但是,没有任何内容被翻译,我尝试模拟下面的 useTranslation 函数:

const useMock : any = [(k: any) => k, {}];
useMock.t = (k: any) => k;
useMock.i18n = {};

jest.mock('react-i18next', () => ({
  // this mock makes sure any components using the translate HoC receive the t function as a prop
  /* tslint:disable-next-line:variable-name */
  useTranslation: () => useMock,
}));
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

typescript i18next jestjs react-i18next ts-jest

6
推荐指数
1
解决办法
2万
查看次数

标签 统计

i18next ×1

jestjs ×1

react-i18next ×1

ts-jest ×1

typescript ×1