fix(websocket): Fix typo in WSContextInit type (#3575)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Ariel-Moroshko · committed by GitHub · parent 3a59d86 · Browse files · 2 files·+11 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+11 added−11 removed
- tests:+8 added−8 removed
- other:+3 added−3 removed
Provenance
- Commit
a90db7c- Tree
01486e2- Author
Ariel-Moroshko <45500865+Ariel-Moroshko@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
3a59d86
2 files changed+11 added−11 removed
modified:src/helper/websocket/index.test.ts+8 added-8 removed
122345638 unmodified lines454647484949505152536 unmodified lines606162636464656667686970717272737475767778787980818283838485868788888990919293949596979898991001011027 unmodified linesimport { Context } from '../../context'import type { WSContestInit } from '.'import type { WSContextInit } from '.'import { WSContext, createWSMessageEvent, defineWebSocketHelper } from '.'
describe('`createWSMessageEvent`', () => { it('Should `createWSMessageEvent` is working for string', () => {38 unmodified lines ws = new WSContext({ close(code, reason) { resolve([code, reason]) }, } as WSContestInit) } as WSContextInit) }) ws.close(0, 'reason') const [code, reason] = await promise expect(code).toBe(0)6 unmodified lines // eslint-disable-next-line @typescript-eslint/no-unused-vars send(data, _options) { resolve(data) }, } as WSContestInit) } as WSContextInit) }) ws.send('Hello') expect(await promise).toBe('Hello') }) it('Should readyState works', () => { const ws = new WSContext({ readyState: 0, } as WSContestInit) } as WSContextInit) expect(ws.readyState).toBe(0) }) it('Should normalize URL', () => { const stringURLWS = new WSContext({ url: 'http://localhost', } as WSContestInit) } as WSContextInit) expect(stringURLWS.url).toBeInstanceOf(URL)
const urlURLWS = new WSContext({ url: new URL('http://localhost'), } as WSContestInit) } as WSContextInit) expect(urlURLWS.url).toBeInstanceOf(URL)
const nullURLWS = new WSContext({ url: undefined, } as WSContestInit) } as WSContextInit) expect(nullURLWS.url).toBeNull() }) it('Should normalize message in send()', () => { let data: string | ArrayBuffer | null = null const wsContext = new WSContext({ // eslint-disable-next-line @typescript-eslint/no-unused-vars send(received, _options) { data = received }, } as WSContestInit) } as WSContextInit)
wsContext.send('string') expect(data).toBe('string')
7 unmodified linesmodified:src/helper/websocket/index.ts+3 added-3 removed
37 unmodified lines38 39 /**40 * An argument for WSContext class41 */42-export interface WSContestInit<T = unknown> {42+export interface WSContextInit<T = unknown> {43 send(data: string | ArrayBuffer, options: SendOptions): void44 close(code?: number, reason?: string): void45 46 raw?: T12 unmodified lines59 /**60 * A context for controlling WebSockets61 */62 export class WSContext<T = unknown> {63- #init: WSContestInit<T>64- constructor(init: WSContestInit<T>) {63+ #init: WSContextInit<T>64+ constructor(init: WSContextInit<T>) {65 this.#init = init66 this.raw = init.raw67 this.url = init.url ? new URL(init.url) : null68 this.protocol = init.protocol ?? null51 unmodified lines