我正在使用该包react-native-localize在应用程序中提供本地化。我已经链接了该库,它可以在设备上正常运行。
问题:
当我测试导入react-native-localize的组件时。我收到错误react-native-localize: NativeModule.RNLocalize is null。为了解决这个空错误,我jest.mock('react-native-localize');在测试文件的顶部调用。但我仍然收到指向NativeModule.RNLocalize is null. 我还提供了README 包中提到的模拟,但无济于事。
import 'react-native';
import React from 'react';
import App from '../App';
// Note: test renderer must be required after react-native.
import renderer from 'react-test-renderer';
import * as RNLocalize from 'react-native-localize';
// mocking the module here with jest.mock
jest.mock('react-native-localize');
it('renders correctly', () => {
renderer.create(<App />);
});
Run Code Online (Sandbox Code Playgroud)
题:
如何解决测试中的 NativeModule.RNLocalize is null 错误?
测试堆栈跟踪:
FAIL __tests__/App-test.js
? Test suite failed …Run Code Online (Sandbox Code Playgroud)