Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jest fails with TypeError: react_native_1.Dimensions.addEventListener is not a function #62

Closed
NathHorrigan opened this issue Oct 20, 2020 · 7 comments

Comments

@NathHorrigan
Copy link

While writing a test for createText I came across an issue regarding missing fields on the Dimensions object.
This seems to be an ongoing issue for the repo, however I am unable to mock the code the module manually:

jest.mock('react-native/Libraries/Utilities/Dimensions', () => {
  return {
    get: () => ({
      width: 375,
      height: 667,
    }),
    addEventListener: jest.fn(),
  };
});

Have you any suggestions?

@NathHorrigan
Copy link
Author

This was fixed by using https://github.com/callstack/react-native-testing-library

@NathHorrigan
Copy link
Author

I think adding some instructions to README regarding testing, in general, would be quite beneficial :)

Apart from the issue, the library looks great, Thanks for your hard work!

@chj-damon
Copy link
Contributor

This was fixed by using https://github.com/callstack/react-native-testing-library

how did you fix this? I'm using react-native-testing-library and still facing this error.

@abeddow91
Copy link

@NathHorrigan I'm getting this error still. Could you provide a little more detail on how you fixed this?

@ludwig-pro
Copy link

still facing this error too

@fortmarek
Copy link
Contributor

We've migrated to the useWindowDimensions from react-native. We mock this hook in the library as such: https://github.com/Shopify/restyle/blob/master/src/test/createRestyleComponent.test.tsx#L53-L55

Please, reopen with reproduction steps if this is still an issue.

@VimalPalanisamy0904
Copy link

@fortmarek is there any way to use useWindowDimensions outside component like in util functions we can use Dimensions.get in util function but after React Native 0.73.8 upgrade jest unit tests are failing for below error so could you or any one please help regarding this issue
TypeError: Dimensions.get is not a function

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

No branches or pull requests

6 participants