Jest-Expo Test fail on MapView.Marker

Was working on Resolving a render test with Peter Piekarczyk.

Note: I only optimized this for iOS so far. Here is the snack link MapView Modal Issue - Snack

The file in question is the MapModal.test.js. When I run the test, I receive the following error Error: TypeError: Cannot read property ‘Marker’ of undefined.

I have tried various methods to get the test to pass. Instead of importing Expo from ‘expo’. I also did
import { MapView } from 'expo and replaced the necessary lines. Still failed on MapeView.Marker

Not sure what else to do. The Component and Modal works on it’s own. Test doesn’t want to pass.

Click on the button on the screen, and the modal should pop up. That is working. Test is not

@ahang - have you tried removing this line: jest.mock('expo', () => 'Expo');? Looks like you are replacing the Expo object with a string 'Expo'. This would create the error you’re seeing, since 'Expo'.MapView would indeed be undefined.

@esamelson
Removing it will result in this error message.

Summary of all failing tests
 FAIL  src/shared/modals/MapModal/MapModal.test.js
  ● renders without crashing

    TypeError: this.map.setNativeProps is not a function

      at MapView._updateStyle (node_modules/react-native-maps/lib/components/MapView.js:470:14)
      at MapView.componentDidMount (node_modules/react-native-maps/lib/components/MapView.js:464:12)
      at commitLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:5097:24)
      at commitAllLifeCycles (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6312:9)
      at Object.invokeGuardedCallback$1 (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1584:10)
      at invokeGuardedCallback (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:1729:29)
      at commitRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:6416:9)
      at completeRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7507:36)
      at performWorkOnRoot (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7457:11)
      at performWork (node_modules/react-test-renderer/cjs/react-test-renderer.development.js:7380:9)

I have also tried replacing it with

jest.doMock('expo', () => {
  const React = require('react');
  return class MockMapView extends React.Component {
    static Marker = props => React.createElement('Marker', props, props.children);
    static propTypes = { children: React.PropTypes.any };

    render() {
      return React.createElement('MapView', this.props, this.props.children);
    }
  };
});

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.