Coder Social home page Coder Social logo

msw-test's Introduction

MSW with React Native

Demo app to illustrate issues with MSW

Issues

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.

  1. It seems the server.use definition is added to the stack but is not triggered when a call is intercepted
  2. It seems the case where server.resetHandler is used with a new definition, the call is no longer intercepted
  3. 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 moment msw is initialised This is a RN initialisation issue. The msw example in the documentation is incorrect and needs improving.
  4. 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.

Demo app

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:

  1. Retrieve a fake URL with the [FakeMovies] button
  2. Retrieve the real URL with the [GetMovies] button - although the behaviour is controlled by the handlers so the real response should not be shown
  3. 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:

  1. for !response.ok (e.g. non 2xx) responses
  2. 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 :-)

Environment

  • MB Pro M2-Max
  • MacOS 14.3.1
  • Emulator iOS v17.0.1

Installed

Detox

Based on detox setup

brew tap wix/brew
brew install applesimutils

yarn add "jest@^29" --dev
yarn add detox --dev
detox init

Msw

Installation according to RN integration

yarn add msw --dev
yarn add fast-text-encoding --dev  
yarn add react-native-url-polyfill --dev

Run

Build

Run the the Detox build first.

detox build -c ios.sim.debug

Metro

Start metro session in terminal

yarn start --reset-cache

Test

Start detox run in seperate terminal

detox test -l trace -c ios.sim.debug starter.test.js 

Logging

Check:

  1. metro terminal for logging
  2. 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.

msw-test's People

Contributors

rayoei avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.