-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac6da8b
commit b5ea6fc
Showing
4 changed files
with
79 additions
and
13 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
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
47 changes: 47 additions & 0 deletions
47
test/node/msw-api/setup-remote-server/on-unhandled-request-default.test.ts
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,47 @@ | ||
// @vitest-environment node | ||
import { HttpResponse, http } from 'msw' | ||
import { setupRemoteServer } from 'msw/node' | ||
import { spawnTestApp } from './utils' | ||
|
||
const remote = setupRemoteServer() | ||
|
||
beforeAll(async () => { | ||
vi.spyOn(console, 'warn').mockImplementation(() => {}) | ||
await remote.listen() | ||
}) | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks() | ||
remote.resetHandlers() | ||
}) | ||
|
||
afterAll(async () => { | ||
vi.restoreAllMocks() | ||
await remote.close() | ||
}) | ||
|
||
it( | ||
'warns on requests not handled by either party be default', | ||
remote.boundary(async () => { | ||
await using testApp = await spawnTestApp(require.resolve('./use.app.js')) | ||
|
||
await fetch(new URL('/resource', testApp.url)) | ||
|
||
// Must print a warning since nobody has handled the request. | ||
expect(console.warn).toHaveBeenCalledWith('') | ||
}), | ||
) | ||
|
||
it( | ||
'does not warn on the request not handled here but handled there', | ||
remote.boundary(async () => { | ||
throw new Error('Complete this') | ||
|
||
await using testApp = await spawnTestApp(require.resolve('./use.app.js')) | ||
|
||
await fetch(new URL('/resource', testApp.url)) | ||
|
||
// Must print a warning since nobody has handled the request. | ||
expect(console.warn).toHaveBeenCalledWith('') | ||
}), | ||
) |
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