Skip to content

Commit cfbd020

Browse files
committed
test(api): assert requesty createMessage listener removal identity
1 parent a2fadca commit cfbd020

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

‎src/api/providers/__tests__/requesty.spec.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ describe("RequestyHandler", () => {
10071007
it("removes the external abort listener when the stream completes", async () => {
10081008
const handler = new RequestyHandler(mockOptions)
10091009
const controller = new AbortController()
1010+
const addSpy = vi.spyOn(controller.signal, "addEventListener")
10101011
const removeSpy = vi.spyOn(controller.signal, "removeEventListener")
10111012
mockCreate.mockImplementationOnce(async () => {
10121013
return asyncStreamFrom([{ id: "1", choices: [{ delta: { content: "done" } }] }])
@@ -1017,7 +1018,12 @@ describe("RequestyHandler", () => {
10171018

10181019
await collectStream(generator)
10191020

1020-
expect(removeSpy).toHaveBeenCalledWith("abort", expect.any(Function))
1021+
// The cleanup path must remove the exact listener that was registered, not just any
1022+
// function: removing a different reference would leave the original abort listener
1023+
// attached to the signal.
1024+
const registeredListener = addSpy.mock.calls[0]?.[1] as EventListener | undefined
1025+
expect(removeSpy).toHaveBeenCalledWith("abort", registeredListener)
1026+
addSpy.mockRestore()
10211027
removeSpy.mockRestore()
10221028
})
10231029

0 commit comments

Comments
 (0)