Skip to content

Commit f0e811f

Browse files
test: stabilize double-check timing
Co-authored-by: me <me@kentcdodds.com>
1 parent 6a3a4c1 commit f0e811f

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

app/utils/misc.use-double-check.test.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function TestComponent({ safeDelayMs = 0 }: { safeDelayMs?: number }) {
2929

3030
test('prevents default on the first click, and does not on the second', async () => {
3131
const user = userEvent.setup()
32-
render(<TestComponent safeDelayMs={50} />)
32+
render(<TestComponent safeDelayMs={200} />)
3333

3434
const status = screen.getByRole('status')
3535
const button = screen.getByRole('button')
@@ -40,13 +40,17 @@ test('prevents default on the first click, and does not on the second', async ()
4040
await user.click(button)
4141
expect(button).toHaveTextContent('You sure?')
4242
expect(status).toHaveTextContent('Default Prevented: yes')
43-
expect(button).toHaveAttribute('data-safe-delay', 'true')
43+
await waitFor(() =>
44+
expect(button).toHaveAttribute('data-safe-delay', 'true'),
45+
)
4446

4547
// clicking it during the safe delay does nothing
4648
await user.click(button)
4749
expect(button).toHaveTextContent('You sure?')
4850
expect(status).toHaveTextContent('Default Prevented: yes')
49-
expect(button).toHaveAttribute('data-safe-delay', 'true')
51+
await waitFor(() =>
52+
expect(button).toHaveAttribute('data-safe-delay', 'true'),
53+
)
5054

5155
await waitFor(() =>
5256
expect(button).toHaveAttribute('data-safe-delay', 'false'),

0 commit comments

Comments
 (0)