我正在使用react测试库来测试我的代码,并且我已经使用i18n.addResourceBundle动态添加了一些翻译。我正在试着测试它
jest.mock('i18n',() => ({ __esModule: true,默认值:{ addResourceBundle: jest.fn() } }))
BUt当我尝试进行快照时,它总是说i18n.addResourceBundle未定义
发布于 2020-06-25 15:15:17
你在不恰当地嘲笑i18next。
i18next的用法如下所示:
import i18next from 'i18next';
export const i18n = i18next.init({
...
// config
...
});
// somewhere else in the code
i18n.addResourceBundle();
//-^ this is an instance of i18next这意味着您需要使用init函数返回一个对象,该函数返回一个使用addResourceBundle的实例。
jest.mock('i18n', () => ({
__esModule: true,
default: {
init(config) {
return {
// this is the instance
addResourceBundle: jest.fn(),
};
},
},
}));https://stackoverflow.com/questions/62563156
复制相似问题