Skip to content

Commit

Permalink
Better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ghengeveld committed Jul 4, 2022
1 parent a9b75cf commit 96fb6c2
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/preview-web/src/PreviewWeb.mockdata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export const mockChannel = {

export const waitForEvents = (
events: string[],
predicate: (...args: any[]) => boolean = () => true
predicate: (...args: any[]) => boolean = () => true,
debugLabel?: string
) => {
// We've already emitted a render event. NOTE if you want to test a second call,
// ensure you call `mockChannel.emit.mockClear()` before `waitFor...`
Expand All @@ -137,7 +138,9 @@ export const waitForEvents = (
events.forEach((event) => mockChannel.on(event, listener));

// Don't wait too long
waitForQuiescence().then(() => reject(new Error('Event was not emitted in time')));
waitForQuiescence().then(() =>
reject(new Error(`Event was not emitted in time: ${debugLabel || events}`))
);
});
};

Expand All @@ -152,8 +155,10 @@ export const waitForRender = () =>
STORY_MISSING,
]);

export const waitForRenderPhase = (phase: RenderPhase) =>
waitForEvents([STORY_RENDER_PHASE_CHANGED], ({ newPhase }) => newPhase === phase);
export const waitForRenderPhase = (phase: RenderPhase) => {
const label = `${STORY_RENDER_PHASE_CHANGED} to ${phase}`;
return waitForEvents([STORY_RENDER_PHASE_CHANGED], ({ newPhase }) => newPhase === phase, label);
};

// A little trick to ensure that we always call the real `setTimeout` even when timers are mocked
const realSetTimeout = setTimeout;
Expand Down

0 comments on commit 96fb6c2

Please sign in to comment.