Problem
Two tests in packages/react/src/components/Toast/toast.test.tsx use this pattern:
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
-
'should transition from shown to hidden' (toast.test.tsx:82-111) — 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.
-
'deactivates aria isolate on unmount' (toast.test.tsx:253-281) — 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:
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.
Problem
Two tests in
packages/react/src/components/Toast/toast.test.tsxuse this pattern:setTimeoutis imported fromtimers/promises(line 2). Its signature issetTimeout(delay, value, options)— the second argument is the resolve value, not a callback. The arrow function holding theexpectis never invoked. Because the promise resolves without throwing, the outerwaitForsucceeds immediately and the inner assertion is dead code.Affected tests
'should transition from shown to hidden'(toast.test.tsx:82-111) — runs once per type viaObject.entries(toastTypes).forEach(...), so 5 dead-assertion test cases. This is the only named coverage of theshow: true → false → 'is--hidden'transition.'deactivates aria isolate on unmount'(toast.test.tsx:253-281) — same pattern, plus two additional issues: it renderstype="info"(which never instantiates anAriaIsolate, so even if the assertion ran it would fail), and it never actually unmounts the component.Proposal
For test 1, replace with the standard
waitForform already used elsewhere in this file:For test 2, rewrite to render
type="action-needed"withshow={true}, capture theunmountfrom the render result, and assertAriaIsolate.prototype.deactivatewas spied and called after unmount.Surfacing
Found while reviewing #2349.