Skip to content

Commit

Permalink
test: rename test for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Mar 24, 2024
1 parent 59a648b commit 32dacec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
34 changes: 34 additions & 0 deletions test/node/ws-api/ws.apply.test.ts
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)
})
24 changes: 0 additions & 24 deletions test/node/ws-api/ws.listen.test.ts

This file was deleted.

0 comments on commit 32dacec

Please sign in to comment.