-
Notifications
You must be signed in to change notification settings - Fork 55
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
Unable to run Jest and V2 with reactNative version 0.73.6 #1729
Comments
Thank you very much for such a detailed report; we are looking into this. |
Hello @dmregister . Thank you for reporting this! We identified the issue with our React Native bundle, which used the That being said, upon further testing, I encountered other obstacles when running jest tests for a React Native app using the non-mocked ably-js. Our React Native bundle relies on various browser APIs to function (WebSocket and XMLHttpRequest, for example). However, the Node environment in which Jest runs its tests does not load any DOM or browser APIs by design, leading to errors like Mocking these browser APIs can become complex quickly. Therefore, I would suggest either mocking the ably client or using your workaround to force Jest to import the node.js ably-js bundle: moduleNameMapper: {
ably: require.resolve('ably'),
}, You can also force Jest to resolve the exports field using the testEnvironmentOptions: {
customExportConditions: ['node'],
}, |
Since ably-js requires certain browser APIs to function correctly, and the Jest testing environment for React Native does not provide them, some additional workarounds are required to make it work. See the comment above for more details. Closing this as completed. |
When running our jest test after upgrading our React Native version to .73, all the tests are failing with:
On react-native version .70, it seems like it was importing the nodejs version rather than the react-native build. This is probably due to RN now supporting exports from the package.json. The quick fix is to force jest to import the nodejs version e.g.
but this is not ideal. Our jest config is using the react-native preset.
Using the example file and applying the attached patch will result in the same error:
https://github.com/ably-labs/ably-js-react-native-example
jest_error_ably.patch
┆Issue is synchronized with this Jira Task by Unito
The text was updated successfully, but these errors were encountered: