Skip to content

Commit 69a1359

Browse files
committed
test(wait-for): validate onTimeout callback customizes timeout error messages
1 parent 1c99145 commit 69a1359

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/__tests__/wait-for.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,20 @@ it('resolves when expectation returns a promise that resolves', async () => {
3131
expect(result).toBe('success');
3232
expect(attemptCount).toBeGreaterThanOrEqual(3);
3333
});
34+
35+
it('calls onTimeout callback with error and uses returned error when provided', async () => {
36+
const customError = new Error('Custom timeout message');
37+
const onTimeout = jest.fn((error: Error) => customError);
38+
39+
await expect(
40+
waitFor(
41+
() => {
42+
throw new Error('Condition not met');
43+
},
44+
{ timeout: 100, onTimeout },
45+
),
46+
).rejects.toThrow('Custom timeout message');
47+
48+
expect(onTimeout).toHaveBeenCalledTimes(1);
49+
expect(onTimeout).toHaveBeenCalledWith(expect.any(Error));
50+
});

test-coverage-progress.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ test(wait-for-element-to-be-removed): Validates waitForElementToBeRemoved resolv
2222
test(matchers/to-have-style): Validates toHaveStyle matcher checks if element has expected style properties - critical matcher users depend on for testing styled components and verifying UI styling. Coverage: 51.38% statements (was 29.16%), 50% branches, 20% functions for to-have-style.ts. Covered main matcher function, style flattening, property comparison logic. Uncovered: error message formatting paths (success case lines 27-41, failure diff lines 48-51, helper functions lines 56-72).
2323
test(matchers/to-be-busy): Validates toBeBusy matcher checks if element is busy via accessibilityState - critical matcher users depend on for testing loading states in components. Coverage: 66.66% statements (was 37.5%), 100% branches, 50% functions for to-be-busy.ts. Covered main matcher function, computeAriaBusy logic, busy and not-busy states. Uncovered: error message formatting (lines 15-22).
2424
test(matchers/to-have-text-content): Validates toHaveTextContent matcher checks if element has expected text content - critical matcher users depend on for verifying text content in components. Coverage: 69.69% statements (was 27.27%), 33.33% branches, 50% functions for to-have-text-content.ts. Covered main matcher function, text content retrieval and matching. Uncovered: error message formatting (lines 22-31).
25+
test(wait-for): Validates waitFor onTimeout callback customizes timeout error messages - critical feature users depend on for customizing error messages when async conditions timeout. Coverage: 67.5% statements (was 65%), 71.42% branches (was 68.96%), 100% functions for wait-for.ts. Covered onTimeout callback invocation and error replacement (lines 184-188). Uncovered: type checking (lines 33-34), fake timers path (lines 47-95), timer switching errors (lines 121-127), non-Error to Error conversion (lines 171-172).

0 commit comments

Comments
 (0)