diff --git a/code/lib/test/src/spy.ts b/code/lib/test/src/spy.ts index 81f5c71eda71..6a97a19c390e 100644 --- a/code/lib/test/src/spy.ts +++ b/code/lib/test/src/spy.ts @@ -18,13 +18,11 @@ export type * from '@vitest/spy'; export { isMockFunction, mocks }; type Listener = (mock: MockInstance, args: unknown[]) => void; -let listeners: Listener[] = []; +const listeners = new Set(); export function onMockCall(callback: Listener): () => void { - listeners = [...listeners, callback]; - return () => { - listeners = listeners.filter((listener) => listener !== callback); - }; + listeners.add(callback); + return () => void listeners.delete(callback); } // @ts-expect-error Make sure we export the exact same type as @vitest/spy