-
-
Notifications
You must be signed in to change notification settings - Fork 469
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
59a648b
commit 32dacec
Showing
2 changed files
with
34 additions
and
24 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,34 @@ | ||
/** | ||
* @vitest-environment node-websocket | ||
*/ | ||
import { ws } from 'msw' | ||
import { setupServer } from 'msw/node' | ||
|
||
const server = setupServer() | ||
|
||
afterEach(() => { | ||
server.close() | ||
}) | ||
|
||
it('does not patch WebSocket class if no event handlers were defined', () => { | ||
server.listen() | ||
|
||
const raw = new WebSocket('wss://example.com') | ||
expect(raw.constructor.name).toBe('WebSocket') | ||
expect(raw).toBeInstanceOf(EventTarget) | ||
}) | ||
|
||
it('does not patch WebSocket class until server.listen() is called', () => { | ||
const api = ws.link('wss://example.com') | ||
server.use(api.on('connection', () => {})) | ||
|
||
const raw = new WebSocket('wss://example.com') | ||
expect(raw.constructor.name).toBe('WebSocket') | ||
expect(raw).toBeInstanceOf(EventTarget) | ||
|
||
server.listen() | ||
|
||
const mocked = new WebSocket('wss://example.com') | ||
expect(mocked.constructor.name).not.toBe('WebSocket') | ||
expect(mocked).toBeInstanceOf(EventTarget) | ||
}) |
This file was deleted.
Oops, something went wrong.