How to use Jest with React Native

后端 未结 3 1651
情书的邮戳
情书的邮戳 2020-12-14 08:17

The testing section of the docs for React Native suggest that Jest is the official way to do unit tests. However, they don\'t explain how to get it setup. Running Jest witho

3条回答
  •  春和景丽
    2020-12-14 09:06

    I got Jest to work for my React Native application, and it is running tests without any problem on files with ES6 and ES7 transforms.

    To get Jest to work, I followed these steps:

    1. Copied the jestSupport folder from the React Native master repo to my react-native folder in node_modules.

    2. Edited the "jest" line in my packages.json to points to the files in the jestSupport folder

    The "jest" line in my packages.json now looks lke this:

    "jest": {
      "scriptPreprocessor": "/node_modules/react-native/jestSupport/scriptPreprocess.js",
      "setupEnvScriptFile": "/node_modules/react-native/jestSupport/env.js",
      "testFileExtensions": [
        "js"
      ],
      "unmockedModulePathPatterns": [
        "source-map"
      ]
    },
    

提交回复
热议问题