# msw-sp

> MSW handlers for mocking SharePoint REST api.

Latest version **1.13.0** (published 2025-02-07) · ISC license · 0 weekly downloads

## Install

```sh
npm install msw-sp
pnpm add msw-sp
yarn add msw-sp
bun add msw-sp
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.13.0 |
| Published | 2025-02-07 |
| First published | 2023-11-13 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Allan Hvam |
| Maintainers | allanhvam |

## Links

- npm: https://www.npmjs.com/package/msw-sp
- Repository: https://github.com/allanhvam/msw-sp
- Homepage: https://github.com/allanhvam/msw-sp#readme
- Issues: https://github.com/allanhvam/msw-sp/issues
- npm.io page: https://npm.io/package/msw-sp

## Recent versions

- 1.13.0 (latest) — 2025-02-07
- 1.12.0 — 2024-10-01
- 1.11.0 — 2024-09-18
- 1.10.0 — 2024-09-11
- 1.9.0 — 2024-09-11
- 1.8.0 — 2024-07-30
- 1.7.0 — 2024-07-29
- 1.6.0 — 2024-06-27
- 1.5.0 — 2024-05-31
- 1.4.0 — 2024-05-10
- 1.3.0 — 2024-04-30
- 1.2.0 — 2024-04-25
- 1.1.0 — 2024-04-17
- 1.0.1 — 2024-04-15
- 1.0.0 — 2023-11-13

## README

# msw-sp

MSW handlers for mocking SharePoint REST api.

## Usage

1. Install `msw` (https://mswjs.io/docs/getting-started)
2. Install `msw-sp`
3. Define your SharePoint model:

```
import { Tenant } from "msw-sp";

const tenant = {
    title: "tenant",
    url: "https://tenant.sharepoint.com",
    sites: {
        "/": {
            rootWeb: {
                title: "Title",
                serverRelativeUrl: "/",
            },
        }
    },
} satisfies Tenant;
```

3. Import `handlers` from `msw-sp`, pass it the tenant model, and give
   the handlers to the specific setup function:

```

// Node.js
import { setupServer } from 'msw/node'
import { handlers } from 'msw-sp';

export const server = setupServer(...handlers({ tenant }));

// Browser
import { setupServer } from 'msw/browser'
import { handlers } from 'msw-sp';

export const worker = setupWorker(...handlers({ tenant }));
```

## Delay

The `handlers` function accepts a `delay` property to simulate real-world client
communication (concept similar to https://mswjs.io/docs/api/delay/). `delay` can be:

-   undefined, nearly instantaneously responses (default behavior)
-   `number`, responses are delayed by specified milliseconds
-   `"real"`, realistic response time
-   `"infinite"`, response is forever pending

Example:

```
...handlers({ tenant, delay: "real" })
```

---
_Source: https://npm.io/package/msw-sp · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
