Skip to content
This repository was archived by the owner on Jul 30, 2020. It is now read-only.

View's measure + other native methods are null #129

Closed
bgneu opened this issue Jun 19, 2020 · 2 comments
Closed

View's measure + other native methods are null #129

bgneu opened this issue Jun 19, 2020 · 2 comments

Comments

@bgneu
Copy link

bgneu commented Jun 19, 2020

  • react-native or expo: react-native
  • native-testing-library version: 5.0.3
  • jest-preset: @testing-library/react-native/jest-preset
  • react-native version: 0.62.2
  • node version: 14.4.0

Relevant code or config:

_updatePosition(callback) {
    if (this._button && this._button.measure) {
      this._button.measure((fx, fy, width, height, px, py) => {
        this._buttonFrame = {
          x: px,
          y: py,
          w: width,
          h: height,
        };
        callback && callback();
      });
    }
  }

this._button is a ref to TouchableOpacity component.

What you did:

Upgraded existing project from RN 0.61.5, where I had this reported issue, to 0.62.2.

With the upgrade, however, it seems like the mock-native-methods are no longer accessible because on close inspectionthis._button.measure === null returns true on tests. This is also true for the other native methods.

What happened:

The measure function is not available, therefore not being called.

Reproduction:

I'll try to update the issue with a repo that reproduces the issue.

Problem description:

The measure method, along with all other native methods mentioned in RN docs should be available on most of the default components provided by React Native.

Suggested solution:

Attempted to look into the @testing-library/react-native preset code, but could not spend too much time as to come up with a solution or improvement.

Can you help us fix this issue by submitting a pull request?

Would love to, but I have some other work priorities which may not allow me to devote the needed time to fix this. If it changes before this is resolved I'll definitely look into it.

@bgneu bgneu changed the title The Views measure + other native methods are null View's measure + other native methods are null Jun 19, 2020
@bgneu
Copy link
Author

bgneu commented Jun 19, 2020

Closing this issue, because as I debugged a bit more the issue is with the Touchable components themselves. In order to get the press fireEvent to work we have to mock TouchableOpacity (see #113 (comment)), however once mocked, attempting to get a reference to the component does not work, which then snowballs into the issue that caused me to create this ticket.

A work around that's working for me now is

jest.mock('react-native/Libraries/Components/Touchable/TouchableOpacity', () => {
  const TouchableOpacity = jest.requireActual(
      'react-native/Libraries/Components/Touchable/TouchableOpacity',
  )
  TouchableOpacity.displayName = 'TouchableOpacity';
  return TouchableOpacity;
});

@bgneu bgneu closed this as completed Jun 19, 2020
@RicardoBrito1938
Copy link

@bgneu thanks, you saved me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants