Skip to content

Commit

Permalink
Make listeners a set
Browse files Browse the repository at this point in the history
  • Loading branch information
kasperpeulen committed Apr 10, 2024
1 parent 176dbee commit f9cb419
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions code/lib/test/src/spy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Listener>();

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
Expand Down

0 comments on commit f9cb419

Please sign in to comment.