Skip to content

Commit

Permalink
making test more solid
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Jan 22, 2024
1 parent 0ab7e7f commit 2d3d6dc
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/LiveComponent/assets/test/controller/render.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,17 @@ describe('LiveController rendering Tests', () => {
if (firstRenderFinishedAt === 0) {
firstRenderFinishedAt = Date.now();
}

// the sleep guarantees that if the 2nd request was correctly
// delayed, its start time will be at least 10ms after the first
// render finished. Without this, even if the 2nd request is
// correctly delayed, the "first render finish" and "second render
// start" times could be the same, because no time has passed.
const sleep = (milliseconds: number) => {
const startTime = new Date().getTime();
while (new Date().getTime() < startTime + milliseconds);
}
sleep(10);
});

test.expectsAjaxCall();
Expand Down

0 comments on commit 2d3d6dc

Please sign in to comment.