Skip to content

Commit ba21068

Browse files
committed
Test random flickering story case
1 parent 67c6a0a commit ba21068

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

stories/html.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ export const RendersReliablyEvenWithFrequentChangesAndMultiplePortals = () => {
200200
// There should be no other errors though.
201201
setTimeout(() => {
202202
setState(!state);
203-
}, 100);
203+
}, 10);
204204

205205
return <div>
206206
Portal flickers between 2 / 3 / nothing here:

tests/html.test.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,32 @@ const storyTests: Record<string, (result: RenderResult) => void | Promise<void>>
158158

159159
expect(container.textContent).toContain('Count is 1');
160160
},
161+
'RendersReliablyEvenWithFrequentChangesAndMultiplePortals': async ({ container }) => {
162+
const getRenderedValue = () => {
163+
const text = container.textContent || '';
164+
const match = text.match(/Portal flickers between 2 \/ 3 \/ nothing here:(\d*)/);
165+
return match ? (match[1] || 'nothing') : 'nothing';
166+
};
167+
168+
const seenValues = new Set<string>();
169+
const valueCounts = { '2': 0, '3': 0, 'nothing': 0 };
170+
171+
for (let i = 0; i < 50; i++) {
172+
await wait(15); // UI code flickers every 10ms
173+
174+
const value = getRenderedValue();
175+
seenValues.add(value);
176+
if (value === '2' || value === '3' || value === 'nothing') {
177+
valueCounts[value]++;
178+
}
179+
180+
expect(['2', '3', 'nothing']).toContain(value);
181+
}
182+
183+
expect(valueCounts['2']).toBeGreaterThanOrEqual(2);
184+
expect(valueCounts['3'] + valueCounts['nothing']).toBeGreaterThanOrEqual(2);
185+
expect(seenValues.size).toBeGreaterThanOrEqual(2);
186+
},
161187
};
162188

163189
// Skipped for now, until we have full test coverage of the stories:

0 commit comments

Comments
 (0)