dequelabs / dequelabs/cauldron

Toast: several tests have assertions that never run due to misuse of timers/promises setTimeout

Open Beginner friendly
#2,359 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
127
Forks
31
Avg merge
2d 12h
Merged PRs (30d)
8

Description

## Problem

Two tests in [`packages/react/src/components/Toast/toast.test.tsx`](https://github.com/dequelabs/cauldron/blob/develop/packages/react/src/components/Toast/toast.test.tsx) use this pattern:

```ts
await waitFor(async () => {
await setTimeout(undefined, () => {
expect(...).toHaveClass('is--hidden');
});
});
```

`setTimeout` is imported from `timers/promises` (line 2). Its signature is `setTimeout(delay, value, options)` — the second argument is the *resolve value*, not a callback. The arrow function holding the `expect` is never invoked. Because the promise resolves without throwing, the outer `waitFor` succeeds immediately and the inner assertion is dead code.

## Affected tests

1. `'should transition from shown to hidden'` ([toast.test.tsx:82-111](https://github.com/dequelabs/cauldron/blob/develop/packages/react/src/components/Toast/toast.test.tsx#L82)) — runs once per type via `Object.entries(toastTypes).forEach(...)`, so 5 dead-assertion test cases. This is the only named coverage of the `show: true → false → 'is--hidden'` transition.

2. `'deactivates aria isolate on unmount'` ([toast.test.tsx:253-281](https://github.com/dequelabs/cauldron/blob/develop/packages/react/src/components/Toast/toast.test.tsx#L253)) — same pattern, plus two additional issues: it renders `type="info"` (which never instantiates an `AriaIsolate`, so even if the assertion ran it would fail), and it never actually unmounts the component.

## Proposal

For test 1, replace with the standard `waitFor` form already used elsewhere in this file:

```ts
await waitFor(() => {
expect(screen.getByTestId('toast')).toHaveClass('Toast', 'Toast--info', 'is--hidden');
});
```

For test 2, rewrite to render `type="action-needed"` with `show={true}`, capture the `unmount` from the render result, and assert `AriaIsolate.prototype.deactivate` was spied and called after unmount.

## Surfacing

Found while reviewing #2349.

Contributor guide

Open the contributing guide

Research direction

Open packages/react/src/components/Toast/toast.test.tsx and run the affected Toast tests first, then compare the two named tests with the existing waitFor usage in that file. Done means the transition assertions execute for each toast type and the action-needed toast verifies AriaIsolate deactivation after unmount.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, react, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
88/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.