Skip to content

Commit

Permalink
docs: add http to extended base (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
SetupCoding authored Dec 9, 2023
1 parent 0740611 commit b0082ff
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/playwright-msw/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,21 @@ If you're using REST API's, all you need to do is provide your handlers to `crea

```typescript
import { test as base, expect } from '@playwright/test';
import { http } from 'msw';
import type { MockServiceWorker } from 'playwright-msw';
import { createWorkerFixture } from 'playwright-msw';

import handlers from './handlers';

const test = base.extend<{
worker: MockServiceWorker;
http: typeof http;
}>({
worker: createWorkerFixture(handlers),
http
});

export { test, expect };
export { expect, test };
```

**Note:** if you're using GraphQL, then it is assumed that the calls are made over HTTP. The default uri for the graphql endpoint is `/graphql`. This can be customized via [configuration](#configuration) object when creating the worker.
Expand All @@ -109,7 +112,7 @@ export { test, expect };
The final step is to use the extended `test` implementation within your playwright tests. e.g. within a [http.spec.ts](https://github.com/valendres/playwright-msw/blob/main/packages/example/tests/playwright/specs/http.spec.ts) file:

```typescript
import { http, delay, HttpResponse } from 'msw';
import { delay, HttpResponse } from 'msw';
import { expect, test } from '../test';

test.describe.parallel("A demo of playwright-msw's functionality", () => {
Expand All @@ -123,6 +126,7 @@ test.describe.parallel("A demo of playwright-msw's functionality", () => {
test.only('should allow mocks to be overridden on a per test basis', async ({
page,
worker,
http
}) => {
await worker.use(
http.get('/api/users', async () => {
Expand Down

0 comments on commit b0082ff

Please sign in to comment.