reactjs - 如何在排毒中使用 react-native-i18n[react-native]
问题描述
我想在 detox 中测试警报消息,并且消息使用 i18n。
const i18n = require("react-native-i18n");
describe("Example", () => {
beforeEach(async () => {
await device.reloadReactNative();
});
it("should show hello screen after tap", async () => {
await element(by.id("btnLogin")).tap();
I18n.t(LocaleKeys.errorMsg_invalidUsername);
await expect(element(by.text(I18n.t(LocaleKeys.errorMsg_invalidUsername)))).toBeVisible();
// await expect(element(by.text("Please input the email and password."))).toBeVisible();
});
});
运行测试并得到以下错误。
测试套件无法运行
/Users/leogeng/Desktop/studentREP/student-app/node_modules/react-native-i18n/index.js:14
export const getLanguages = () => RNI18n.getLanguages();
^^^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (../node_modules/jest-runtime/build/script_transformer.js:305:17)
at Object.<anonymous> (firstTest.spec.js:1:114)
at Generator.next (<anonymous>)
然后我添加以下代码开玩笑:
{
"preset": "react-native",
"transformIgnorePatterns": [
"/node_modules/(?!(react-native(.*)?/|native-base(.*)?/|react-navigation/))"
]
}
并再次得到错误:
Validation Error:
Module <rootDir>/node_modules/react-native/jest/setup.js in the setupFiles option was not found.
实际上,我确认 node_modules/react-native/jest 中存在“setup,js”。我不知道为什么会发生错误,有人可以帮助我吗?谢谢
解决方案
很可能是因为您使用的是旧版本node
,请尝试更新并查看它是否可以解决问题。此外,它与 Jest 单元测试完全无关,Jest
如果您对 Jest 单元测试没有任何问题,您可能应该恢复修改 Jest 设置的尝试;无论如何,它不会解决排毒问题。
如果您有某些要求或原因迫使您保留node
特定的旧版本,您可以通过不同的方式执行测试来绕过它:仅为 e2e 测试创建一个演示屏幕(或者甚至为 e2e 创建一个完整的演示项目) ,在演示屏幕中,您可以有一个按钮来执行您需要的i18n
操作(更改语言环境或其他),并在detox
测试中点击此“演示”按钮,然后再测试您真正想要的内容。
推荐阅读
- python - 如何“实时”获取浏览器中正在访问的 URL?
- python - 如何让我的不和谐机器人对我的消息做出反应
- docker - sql容器问题的Docker格式化密码
- python - 训练模型后 Jupyter Notebook GPU 内存释放
- typescript - 键的打字稿联合类型,字典值的推断类型
- python - FastCGI 随机崩溃
- excel - VBA:AddDate + time 更改格式
- java - Android MediaPlayer 在指定时间段内播放 URI?
- javascript - 这种函数结构会减慢应用程序的速度吗?
- java - 重置 OutputStream 以便更新的变量发送