-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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 test fails because of incorrectly loaded react native modules #13167
Comments
Is there any reason why |
Hi @itsramiel, |
@itsramiel, wanted to follow up and see if you had a chance to try adding a mock as mentioned in the issue referenced in @ashwinkumar6's comment. Let us know if you're still having this issue and if we can help, thanks! |
Yeah I already use the following mock: jest.mock('@aws-amplify/react-native', () => {
const original = jest.requireActual('@aws-amplify/react-native');
return {
...original,
loadAsyncStorage: jest.fn(),
loadNetInfo: jest.fn(() => ({
addEventListener: jest.fn(),
})),
};
}); but I was wondering if there is a plan to handle that internally |
Before opening, please confirm:
JavaScript Framework
React Native
Amplify APIs
DataStore
Amplify Version
v6
Amplify Categories
Not applicable
Backend
None
Environment information
Describe the bug
When testing a react native app with jest, I get the following error message:
Ensure
@react-native-async-storage/async-storageis installed and linked.
with the source being
at loadAsyncStorage (node_modules/@aws-amplify/react-native/src/moduleLoaders/loadAsyncStorage.ts:22:15)
The issue is that when loading the module, the module is loaded with
require().default
:amplify-js/packages/react-native/src/moduleLoaders/loadAsyncStorage.ts
Lines 10 to 11 in 2b71e29
But the mock that is shipped with
react-native-async-storage/async-storage
is a common js object with no default property, sorequire('@react-native-async-storage/async-storage')?.default
is always undefind in jest, butrequire('@react-native-async-storage/async-storage')
is definedExpected behavior
I expect to not get the error
Ensure
@react-native-async-storage/async-storageis installed and linked.
since it is installed and mocked properly according to the library docs.Reproduction steps
yarn
yarn test
and check the errorCode Snippet
// Put your code below this line.
Log output
aws-exports.js
No response
Manual configuration
No response
Additional configuration
No response
Mobile Device
No response
Mobile Operating System
No response
Mobile Browser
No response
Mobile Browser Version
No response
Additional information and screenshots
No response
The text was updated successfully, but these errors were encountered: