Demo app to illustrate issues with MSW
Originally this demo app was made for reported issue #1, but while debugging further, more issues seem to exist with handling of the interception and subsequent handling of the defined responses.
- It seems the server.use definition is added to the stack but is not triggered when a call is intercepted
- It seems the case where server.resetHandler is used with a new definition, the call is no longer intercepted
It seems that handler definition for fake_reactnative.dev/movies.json is not called when the app is loading while it is expected to be used from the momentThis is a RN initialisation issue. Themsw
is initialisedmsw
example in the documentation is incorrect and needs improving.- It seems that the handler with the definition once is always called while the expectation is that the 2nd and subsequent calls would trigger the next definition for
reactnative.dev/movies.json
.
In short: there seem to be issues with the handling of intercepted calls and the processing of the defined responses.
The app is based on the React Native Quick starter
demo: React Native project. Where a movie list is retrieved. This app has been modified to:
- Retrieve a fake URL with the [FakeMovies] button
- Retrieve the real URL with the [GetMovies] button - although the behaviour is controlled by the handlers so the
real
response should not be shown - Reset the list with the [Clear] button - no handler or API call is used here
The handling of the specific fetch
in the app is expanded with error messages, to be shown in the list:
- for
!response.ok
(e.g. non2xx
) responses - and the
http.error()
response (e.g. no network)
Which can be used to further check the actual behaviour of the defined handler responses.
No special care has been taken in cleaning up or minimising code duplication :-)
- MB Pro M2-Max
- MacOS 14.3.1
- Emulator iOS v17.0.1
Based on detox setup
brew tap wix/brew
brew install applesimutils
yarn add "jest@^29" --dev
yarn add detox --dev
detox init
Installation according to RN integration
yarn add msw --dev
yarn add fast-text-encoding --dev
yarn add react-native-url-polyfill --dev
Run the the Detox build first.
detox build -c ios.sim.debug
Start metro session in terminal
yarn start --reset-cache
Start detox run in seperate terminal
detox test -l trace -c ios.sim.debug starter.test.js
Check:
- metro terminal for logging
- detox terminal for logging (for additional detox logging, see
detox
doc.)
Note: removed original included logging from this file as that is no longer representative after the app changes.