Skip to content

Following the React Native integration docs leads to errors #506

@tomgransden

Description

@tomgransden

Hello, I have been trying to follow the React Native integration documents and assorted Github issues but I cannot get the integration working. I'd really love to as I want to run MSW for my E2E tests to mock the backend. I have verified MirageJS works as intended but we already use MSW for unit tests so want to try and get it working.

React Native version: 0.77.2
MSW version: 2.10.4

Any help would be appreciated.

Code samples:

// msw.polyfills.js
import 'fast-text-encoding';
import 'react-native-url-polyfill/auto';
// src/mocks/server.js
import { setupServer } from 'msw/native';

import { accountHandlers } from '../test/servers/msw/handlers/ecomm/account';

const handlers = [...accountHandlers];

export const server = setupServer(...handlers);
// index.js
/**
 * @format
 */
import 'intl-pluralrules';
import { AppRegistry } from 'react-native';
import 'react-native-gesture-handler';

import { name as appName } from './app.json';
import App from './src/App';

if (__DEV__) {
  import('./reactotron.config')
    // eslint-disable-next-line no-console
    .then(() => console.log('Reactotron Configured'))
    // eslint-disable-next-line no-console
    .catch(() => console.log('Reactotron failed to initialize'));
}

async function enableMocking() {
  if (!__DEV__) {
    return;
  }

  await import('./msw.polyfills');
  const { server } = await import('./src/mocks/server');
  server.listen();
}

enableMocking().then(() => {
  AppRegistry.registerComponent(appName, () => App);
});

Errors encountered:

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions