Skip to content

Commit

Permalink
fix: prevent race conditions when waiting for updates from fireEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Apr 20, 2020
1 parent 8899ee7 commit 92fd78f
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
fireEvent as originalFireEvent,
EventType,
FireFunction as originalFireFunction,
FireObject as originalFireObject
FireObject as originalFireObject,
} from "@testing-library/dom";

export interface EventRecord {
Expand All @@ -28,7 +28,7 @@ export const INTERNAL_EVENTS = [
"render",
"mount",
"update",
"destroy"
"destroy",
] as const;

export type InternalEventNames = typeof INTERNAL_EVENTS[number];
Expand Down Expand Up @@ -75,9 +75,7 @@ function failIfNoWindow() {
}
}

const setImmediate = global.setImmediate || setTimeout;
function waitForBatchedUpdates() {
// TODO: this waits for a possible update using setTimeout(0) which should
// be sufficient, but ideally we would hook into the Marko lifecycle to
// determine when all pending updates are complete.
return new Promise(resolve => setTimeout(resolve, 0));
return new Promise((resolve) => setImmediate(() => setImmediate(resolve)));
}

0 comments on commit 92fd78f

Please sign in to comment.