react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Test fails because new `isPointerEventEnabled` prevents handler from getting called

Open ccfz opened this issue 4 years ago • 1 comments

Describe the bug

After upgrading from 0.71 to 0.72 one of my test fails because fireEvent no longer triggers the event. If I disable the new isPointerEventEnabled check the test passes again.

Steps to Reproduce

I am mocking react-native-maps like so:

/* eslint-disable no-shadow, max-classes-per-file */
const React = jest.requireActual('react');
const MapView = jest.requireActual('react-native-maps');
/* eslint-enable no-shadow */

const mockShowCallout = jest.fn();

// eslint-disable-next-line react/prefer-stateless-function, react/no-multi-comp
class MockMarker extends React.Component {
  constructor(props) {
    super(props);

    this.showCallout = mockShowCallout;
  }

  render() {
    const { children } = this.props;

    return React.createElement('Marker', this.props, children);
  }
}

// eslint-disable-next-line react/prefer-stateless-function, react/no-multi-comp
class MockMapView extends React.Component {
  static PROVIDER_GOOGLE = 'google';

  render() {
    const { children } = this.props;

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

MockMarker.propTypes = MapView.Marker.propTypes;
MockMapView.propTypes = MapView.propTypes;
MockMapView.Marker = MockMarker;
MockMapView.Callout = MapView.Callout;
MockMapView.exposedMarkerShowCallout = mockShowCallout;

module.exports = MockMapView;

The MapView implements the event onRegionChangeComplete which is what I trigger in the test like so: fireEvent(wrapper.UNSAFE_getByType(RNMapView), 'RegionChangeComplete');

Screenshots

Versions

    @testing-library/react-native: ^7.2.0 => 7.2.0 
    react: 17.0.1 => 17.0.1 
    react-native: 0.63.4 => 0.63.4 
    react-test-renderer: ^17.0.1 => 17.0.1 

ccfz avatar Mar 15 '21 11:03 ccfz

Would you like to investigate this a little more and contribute a fix maybe? :)

thymikee avatar Mar 15 '21 11:03 thymikee

@ccfz could you verify that the issue you reported does still occur on the latest version of RNTL (& React Native, React, React Test Renderer). If so, could you please provide repro repository hopefully based on ours examples/basic app in our repo.

mdjastrzebski avatar Sep 26 '22 12:09 mdjastrzebski

It seems that it should be fixed by #906, which restricted pointer checks just to press event.

mdjastrzebski avatar Oct 16 '22 08:10 mdjastrzebski