【问题标题】:jest error: const warnedKeys: {[string]: boolean} = {};开玩笑的错误: const warnKeys: {[string]: boolean} = {};
【发布时间】:2021-03-05 01:07:04
【问题描述】:

如果我运行 yarn test,它运行 jest,我会收到以下错误:

C:\react-native-project\node_modules\react-native\Libraries\Utilities\warnOnce.js:15
    const warnedKeys: {[string]: boolean} = {};

但这只有在我关注react-native-testing-librarydirections 时才会发生:

然后使用 setupFilesAfterEnv 选项自动将其添加到您的笑话测试中 jest.config.js 文件:

如果我删除该文件,我将不会得到 that 错误,并且我可以运行简单的测试。当我删除文件时,测试运行但AsyncStorage 未被识别,因此测试仍然无法运行。我有AsyncStorage。它已安装并且应用程序可以运行,但我想添加组件测试。我还注意到该文件 jest.config.js 在测试项目本身中明显缺失。是否有任何文档或工作示例?我宁愿不做我的项目和测试项目的差异。是否有更详细或可靠的测试框架/模块可用?

【问题讨论】:

    标签: react-native testing jestjs react-native-testing-library


    【解决方案1】:

    我可以通过遵循 npm 包名称为 @testing-library/react-native 的 React Native 测试库的 documentation 来获得工作测试,不要与 npm 包名称为 @987654325 的 React Native 测试库混淆@。这两个包都允许测试组件,并且由 React-Native documentation 推荐,但是按照说明进行操作时,这个包可以工作。它还具有instructions“定义自定义渲染方法,包括全局上下文提供程序、数据存储等”,因此使用AsyncStorage 等测试组件应该不成问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-04-26
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      • 2021-07-22
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多