Skip to content

Commit

Permalink
test: ensure response/end are not emitted
Browse files Browse the repository at this point in the history
  • Loading branch information
kettanaito committed Apr 12, 2024
1 parent a192a3a commit 3510477
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/modules/http/compliance/http-res-readable.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ it('supports ReadableStream as a mocked response', async () => {
})

it('forwards ReadableStream errors to the request', async () => {
const responseListener = vi.fn()
const endListener = vi.fn()
interceptor.once('request', ({ request }) => {
const stream = new ReadableStream({
start(controller) {
Expand All @@ -47,11 +49,16 @@ it('forwards ReadableStream errors to the request', async () => {
})

const request = http.get('http://example.com/resource')
request.on('response', responseListener)
request.on('end', endListener)

const requestError = await vi.waitFor(() => {
return new Promise<Error>((resolve) => {
request.on('error', resolve)
})
})

expect(requestError).toEqual(new Error('stream error'))
expect(responseListener).not.toHaveBeenCalled()
expect(endListener).not.toHaveBeenCalled()
})

0 comments on commit 3510477

Please sign in to comment.