Skip to content

Commit

Permalink
Clear timeout after usage
Browse files Browse the repository at this point in the history
  • Loading branch information
valainisgt committed Aug 1, 2023
1 parent 7560c3e commit 869dca1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,14 @@ expect.extend({

const waitDelay = options?.timeout ?? WAIT_DELAY;

let timeoutId;
const messageOrTimeout = await Promise.race([
ws.nextMessage,
new Promise((resolve) => setTimeout(() => resolve(TIMEOUT), waitDelay)),
new Promise((resolve) => {
timeoutId = setTimeout(() => resolve(TIMEOUT), waitDelay);
}),
]);
clearTimeout(timeoutId);

if (messageOrTimeout === TIMEOUT) {
return {
Expand Down

0 comments on commit 869dca1

Please sign in to comment.