-
-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add .use() replacement regression tests (#2145)
- Loading branch information
1 parent
7cf34c1
commit ec70ba9
Showing
3 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { http, HttpResponse } from 'msw' | ||
import { setupWorker } from 'msw/browser' | ||
|
||
const worker = setupWorker() | ||
worker.start() | ||
|
||
worker.use( | ||
http.get('/v1/issues', () => { | ||
return HttpResponse.text('get-body') | ||
}), | ||
) | ||
|
||
worker.use( | ||
http.post('/v1/issues', () => { | ||
return HttpResponse.text('post-body') | ||
}), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* @see https://github.com/mswjs/msw/issues/2129 | ||
*/ | ||
import { test, expect } from '../../playwright.extend' | ||
|
||
test('handles a stream response without throwing a timeout error', async ({ | ||
loadExample, | ||
fetch, | ||
}) => { | ||
await loadExample(require.resolve('./2129-worker-use.mocks.ts')) | ||
|
||
const getResponse = await fetch('/v1/issues') | ||
expect(await getResponse.text()).toBe('get-body') | ||
|
||
const postResponse = await fetch('/v1/issues', { method: 'POST' }) | ||
expect(await postResponse.text()).toBe('post-body') | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* @vitest-environment node | ||
* @see https://github.com/mswjs/msw/issues/2129 | ||
*/ | ||
import { http, HttpResponse } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
|
||
const server = setupServer() | ||
|
||
beforeAll(async () => { | ||
server.listen() | ||
}) | ||
|
||
afterEach(() => { | ||
server.resetHandlers() | ||
}) | ||
|
||
afterAll(async () => { | ||
server.close() | ||
}) | ||
|
||
it('does not override existing handlers when adding override for a different method', async () => { | ||
server.use( | ||
http.get('http://localhost/v1/issues', () => { | ||
return HttpResponse.text('get-body') | ||
}), | ||
) | ||
server.use( | ||
http.post('http://localhost/v1/issues', () => { | ||
return HttpResponse.text('post-body') | ||
}), | ||
) | ||
|
||
const geetResponse = await fetch('http://localhost/v1/issues') | ||
expect(await geetResponse.text()).toBe('get-body') | ||
|
||
const postResponse = await fetch('http://localhost/v1/issues', { | ||
method: 'POST', | ||
}) | ||
expect(await postResponse.text()).toBe('post-body') | ||
}) |