Rki*_*g14 6 typescript i18next jestjs react-i18next ts-jest
我的 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)
我究竟做错了什么?
创建一个模拟文件:__mocks__/react-i18next.useTranslation.js内容如下:
module.exports = () => {
return () => ({
t: key => key
})
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19591 次 |
| 最近记录: |