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

docs: add http to extended base #83

Merged
merged 1 commit into from
Dec 9, 2023
Merged
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
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
Loading