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

MSW listen() doesn't work on Expo React Native app #1408

Closed
4 tasks done
fregayeg opened this issue Sep 18, 2022 · 7 comments · Fixed by #1520
Closed
4 tasks done

MSW listen() doesn't work on Expo React Native app #1408

fregayeg opened this issue Sep 18, 2022 · 7 comments · Fixed by #1520
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node

Comments

@fregayeg
Copy link

fregayeg commented Sep 18, 2022

Prerequisites

Environment check

  • I'm using the latest msw version
  • I'm using Node.js version 14 or higher

Node.js version

v16.17.0

Reproduction repository

https://github.com/fregayeg/optional-proj

Reproduction steps

  1. Run yarn install
  2. Run expo start -c and wait the web server to be ready.
  3. Once server is up, open navigator on http://localhost:19002
  4. Scan QR code on device or on Android/iOS if you have Android studio or xCode installed.
  5. The app must be running under Expo Go in your device or emulator.
  6. Once its ready, it must be open.

Current behavior

Actually, following your examples and discussion about React Native support, I've made a sample app, that must call and endpoint through something called redux-toolkit query (equivalent to React Query, Apollo etc...). The behavior is: When I open the app I get my main screen (ui) as expected: a bottom tab navigator with exactly 2 sub-screens. When I go the 2nd screen where the API call is, I get nothing and no errors are printed out on console.

Expected behavior

When I open the app I get my 1st screen (ui) as expected: a bottom tab navigator with exactly 2 sub-screens. If I tap on 2nd tab, I go to the screen where the api call is, and then I must see a loading indicator then a list of items must appear instead, without errors.

@fregayeg fregayeg added bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node labels Sep 18, 2022
@fregayeg
Copy link
Author

Hi again! after many tried, I've figured out a way to make it work! 😆 I appreciate the way how you made msw work for RN apps tbh. Thus, I close this issue as it doesn't have any sense as it I know now.

You can see my answer on Expo Forum, where I asked same a similar question 😄 .

Thanks for you attention. 🙏

@mwood23
Copy link

mwood23 commented Jan 15, 2023

@fregayeg I can't thank you enough for this. MSW would silently fail and thought I was going crazy over here.

@kettanaito
Copy link
Member

Okay, so the silently failing part is definitely not fine.

I think MSW should check if the global URL construct exists and if it's not, throw an exception with suggestion steps to use a polyfill.

The fact that you need to use msw/node is referenced in the docs, I believe, but we need to create a standalone "Integration > React Native" page (looking forward to this in the next docs).

Is there anything else I'm missing?

@kettanaito
Copy link
Member

If anybody could give #1520 a review, I'd be thankful. Let's improve the experience around React Native polyfills.

@fregayeg
Copy link
Author

Hello @kettanaito ! Thank you for this good job! I didn't see the updates sincel last week sorry. Could you please tell me if I should do something else ?

@fregayeg
Copy link
Author

fregayeg commented Jan 24, 2023

Ok maybe I'm late. In order to help people understand what is the minimal setup to run React Native with MSW, I recommend to use Expo, it makes the task straighforward and pretty simple.

I suggest to visit my expo-msw sample , its linked to my personal github.

thanks all

@kettanaito
Copy link
Member

Released: v1.0.0 🎉

This has been released in v1.0.0!

Make sure to always update to the latest version (npm i msw@latest) to get the newest features and bug fixes.


Predictable release automation by @ossjs/release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs:triage Issues that have not been investigated yet. scope:node Related to MSW running in Node
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants