Skip to content

Commit

Permalink
test: ensure target is set to EventSource instance
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Dec 7, 2024
1 parent eddb83c commit bcf0945
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,27 @@ export function registerTests(options: {
await deferClose(es)
})

test('`target` on open, message and error events is the EventSource instance', async () => {
const onOpen = getCallCounter({name: 'onOpen'})
const onMessage = getCallCounter({name: 'onMessage'})
const onError = getCallCounter({name: 'onError'})
const es = new OurEventSource(`${baseUrl}:${port}/end-after-one`)

es.addEventListener('open', onOpen)
es.addEventListener('progress', onMessage)
es.addEventListener('error', onError)

await onOpen.waitForCallCount(1)
await onMessage.waitForCallCount(1)
await onError.waitForCallCount(1)

expect(onOpen.lastCall.lastArg.target).toBe(es)
expect(onMessage.lastCall.lastArg.target).toBe(es)
expect(onError.lastCall.lastArg.target).toBe(es)

await deferClose(es)
})

test('can connect using URL string only', async () => {
const es = new OurEventSource(`${baseUrl}:${port}/`)
const onMessage = getCallCounter({name: 'onMessage'})
Expand Down

0 comments on commit bcf0945

Please sign in to comment.