我正在尝试让Jest与我的React应用一起工作,但是在运行'sudo npm run test'时出现此错误:
FAIL __tests__/App.test.js
● Test suite failed to run
TypeError: Cannot read property 'directEventTypes' of undefined
at Object.directEventTypes (node_modules/react-native-gesture-handler/GestureHandler.js:47:24)
at Object.<anonymous> (node_modules/react-native-gesture- handler/Swipeable.js:11:1)
我四处摸索,发现只有在我从测试文件中的App.js中导入App时,这种情况才会发生:
import App from '../App';
describe('<App />', () => {
it('has 1 child', () => {
const tree = renderer.create(<App />).toJSON();
expect(tree.children.length).toBe(1);
..
我四处搜寻,似乎没人能解决这个问题。
我尝试了https://github.com/react-navigation/react-navigation/issues/5264和https://github.com/kmagiera/react-native-gesture-handler/issues/344#issuecomment-440572584处的所有内容,但没有任何效果。