Skip to content

Commit 1416ccd

Browse files
committed
chore: more tests
1 parent d4c6303 commit 1416ccd

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/__tests__/wait-for.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,34 @@ test('waitFor throws if expectation is not a function', async () => {
316316
waitFor('not a function'),
317317
).rejects.toThrowErrorMatchingInlineSnapshot(`"Received \`expectation\` arg must be a function"`);
318318
});
319+
320+
test.each([false, true])(
321+
'waitFor throws clear error when switching from fake timers to real timers (legacyFakeTimers = %s)',
322+
async (legacyFakeTimers) => {
323+
jest.useFakeTimers({ legacyFakeTimers });
324+
325+
const waitForPromise = waitFor(() => {
326+
// Switch to real timers during waitFor - this should trigger an error
327+
jest.useRealTimers();
328+
throw new Error('test');
329+
});
330+
331+
await expect(waitForPromise).rejects.toThrow(
332+
'Changed from using fake timers to real timers while using waitFor',
333+
);
334+
},
335+
);
336+
337+
test('waitFor throws clear error when switching from real timers to fake timers', async () => {
338+
jest.useRealTimers();
339+
340+
const waitForPromise = waitFor(() => {
341+
// Switch to fake timers during waitFor - this should trigger an error
342+
jest.useFakeTimers();
343+
throw new Error('test');
344+
});
345+
346+
await expect(waitForPromise).rejects.toThrow(
347+
'Changed from using real timers to fake timers while using waitFor',
348+
);
349+
});

0 commit comments

Comments
 (0)