-
-
Notifications
You must be signed in to change notification settings - Fork 181
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
Documentation missing on how to integrate with Expo App Router #372
Comments
Do you have a working example of MSW with expo by chance? |
import { registerRootComponent } from 'expo';
import { ExpoRoot } from 'expo-router';
export const App = () => {
const ctx = require.context('./src/app');
return <ExpoRoot context={ctx} />;
};
async function enableMocking() {
if (!__DEV__) {
return;
}
await import('./msw.polyfills');
const { server } = await import('./src/server');
server.listen();
}
enableMocking().then(() => {
registerRootComponent(App);
}); |
Not sure if this will fix everything for you but I found this answer very helpful to get my implementation up and running 😄
I can then call |
Trying to get this working myself and not having much luck. I tried all suggestions above & from the current docs.
when MSW tries to mock a request, so I dunno if it's missing some polyfill somewhere? I made a minimal reproduction here: https://github.com/vonkanehoffen/msw-minimal Same story when I:
Any ideas @kettanaito or anyone? Presume I'm doing something wrong but no idea what 😬 |
As of today, The React Native integration documentation recommends delaying application initialization until the mocks are loaded like so:
However when using Expo App router the entry point of the application is internal to the library and not available to freely configure.
For apps using App Router, Expo recommends placing initialization code in the RootLayout file instead, but it would be helpful if there is an official recommendation from MSW on how avoid potential race conditions related to app initialization.
The text was updated successfully, but these errors were encountered: