在JEST中模仿使用翻译I18N不起作用 [英] Mocking useTranslation for i18n in JEST not working
本文介绍了在JEST中模仿使用翻译I18N不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Reaction组件使用I18Next中的翻译,我正在尝试使用JEST为其创建测试。但是,没有任何内容被翻译,我尝试了模拟下面的useTranslating函数:
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,
}));
我做错了什么?
推荐答案
创建模拟文件:__mocks__/react-i18next.useTranslation.js
,内容如下:
module.exports = () => {
return () => ({
t: key => key
})
}
这篇关于在JEST中模仿使用翻译I18N不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文