1.4.0 • Published 3 days ago

msw-sp v1.4.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 days ago

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;
  1. Import handlers from msw-sp, pass it the tenant model, and give the handlers to the specific setup function:
import { handlers } from 'msw-sp';

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

// Browser
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" })
1.4.0

3 days ago

1.3.0

13 days ago

1.2.0

17 days ago

1.1.0

25 days ago

1.0.1

28 days ago

1.0.0

6 months ago