如何解决不变式违规错误:本机模块不能为null()

时间:2019-05-29 14:45:24

标签: javascript reactjs unit-testing react-native jestjs

我开始开玩笑地测试react native应用程序我开始测试App.js文件并发现节点模块出现“依赖”错误。但是我无法解决的错误之一就是这个。

enter image description here

我不理解错误,也不知道如何解决

__tests__/App.js

import 'react-native'
import React from 'react';
import renderer from 'react-test-renderer';
import App from '../App';


describe('Some component', () => {
  beforeAll(() => {
    jest.mock('@react-native-community/async-storage');

  });

  it('renders correctly', () => {
    const tree = renderer.create(
        <App/>
    ).toJSON();
    expect(tree).toMatchSnapshot();
  });
});

package.json

...    
"jest": {
        "preset": "react-native",
        "cacheDirectory": "./cache",
        "coveragePathIgnorePatterns": [
          "./app/utils/vendor"
        ],
        "coverageThreshold": {
          "global": {
            "statements": 80
          }
        },
        "transformIgnorePatterns": [
          "/node_modules/(?!react-native|react-clone-referenced-element|react-navigation|native-base-shoutem-theme|native-base|lodash|static-container|@react-navigation|react-native-rfid-nfc-scanner)"
        ],
        "setupFiles": [
          "./node_modules/react-native-gesture-handler/jestSetup.js"
        ]
      },
...

0 个答案:

没有答案