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

Adds "React Native" integration page #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions docs/getting-started/integrate/node.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ $ touch src/mocks/server.js
In the `server.js` file we are going to create a server instance with our request handlers defined earlier.

<Action>
Import <code>setupServer</code> function from the <code>msw</code> package and
create a server instance with previously defined request handlers
Import <code>setupServer</code> function from the <code>msw/node</code>{' '}
package and create a server instance with the previously defined request
handlers
</Action>

```js showLineNumbers focusedLines=2,7-8
Expand Down
55 changes: 55 additions & 0 deletions docs/getting-started/integrate/react-native.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
title: React Native
order: 27
---

## Pre-requisites

### URL polyfill

The `URL` class in React Native is not fully compliant with the [URL specification](https://url.spec.whatwg.org). This may lead to all sorts of unexpected behavior, as Mock Service Worker creates and operates with URL instances on runtime.

<Action>Use a specification-compliant URL class polyfill</Action>

Here are some of the recommended polyfills:

- [`react-native-url-polyfill`](https://github.com/charpeni/react-native-url-polyfill)

## Configure server

Let's create a file in our mock definition directory (`src/mocks`) where we would configure our request mocking server.

<Action>
Create a <code>src/mocks/server.js</code> file
</Action>

```bash
$ touch src/mocks/server.js
```

In the `server.js` file we are going to create a server instance with our request handlers defined earlier.

<Action>
Import <code>setupServer</code> function from the <code>msw/native</code>{' '}
package and create a server instance with the previously defined request
handlers
</Action>

```js showLineNumbers focusedLines=2,6
// src/mocks/server.js
import { setupServer } from 'msw/native'
import { handlers } from './handlers'

// This configures a request mocking server with the given request handlers.
export const server = setupServer(...handlers)
```

## Setup

### Runtime

> Explain how to use MSW for development.

### Testing

- Repeat NodeJS setup.