wix / react-native-ui-lib

UI Components Library for React Native
https://wix.github.io/react-native-ui-lib/
MIT License
6.5k stars 706 forks source link

Error when testing with Jest: TypeError: (0 , _reactNative.requireNativeComponent) is not a function #2584

Closed 3210jr closed 1 year ago

3210jr commented 1 year ago

Description

When running jest tests for my components with @testing-library/react-native and jest, I get the error:

TypeError: (0 , _reactNative.requireNativeComponent) is not a function

      3 | import { observer } from "mobx-react-lite"
      4 | import { format } from "date-fns"
    > 5 | import { View, Button } from "react-native-ui-lib"

For seemingly any imported components from "react-native-ui-lib"

Related to

Steps to reproduce

  1. Import a button or view or textfield from "react-native-ui-lib" into any one of your screens or components: import { View, Button, TextField } from "react-native-ui-lib"
  2. Set up testing with Jest and @testing-library/react-native
  3. Create a basic smoke test for the component - test test doesnt matter because it never runs since the error is thrown before the test starts
  4. Run yarn test or whichever command is set up for running jest

Expected behavior

I expected that the test would run and either fail or pass

Actual behavior

Instead I just get the above mentioned error

More Info

Screenshots/Video

Screenshot 2023-05-09 at 1 19 31 AM

Environment

Affected platforms

Thanks for all the work you all have put into the library!

3210jr commented 1 year ago

Adding react-native-ui-lib to the transformIgnorePatterns fixes this issue. Which is great but now facing another issue:

 /path/to/app/node_modules/react-native-ui-lib/src/style/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){export { default as Colors } from "./colors";
                                                                                             ^^^^^^

    SyntaxError: Unexpected token 'export'
stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.