Skip to content

Commit 511f07b

Browse files
committed
.
1 parent b16334c commit 511f07b

File tree

2 files changed

+17
-21
lines changed

2 files changed

+17
-21
lines changed

src/__tests__/act.test.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,32 +52,28 @@ test('should be able to await act when promise rejects', async () => {
5252

5353
test('should restore act environment when callback throws synchronously', async () => {
5454
const previousEnvironment = getIsReactActEnvironment();
55-
55+
5656
const testError = new Error('Synchronous error in act');
57-
58-
try {
59-
await act(() => {
57+
58+
await expect(
59+
act(() => {
6060
throw testError;
61-
});
62-
// Should not reach here
63-
expect(true).toBe(false);
64-
} catch (error) {
65-
expect(error).toBe(testError);
66-
}
67-
61+
}),
62+
).rejects.toBe(testError);
63+
6864
// Verify the act environment was restored even after error
6965
expect(getIsReactActEnvironment()).toBe(previousEnvironment);
7066
});
7167

7268
test('should restore act environment when callback returns non-promise value', async () => {
7369
const previousEnvironment = getIsReactActEnvironment();
74-
70+
7571
// Call act with a callback that returns a non-promise value
7672
// This tests the else branch in withGlobalActEnvironment
7773
const result = await act(() => {
7874
return 42;
7975
});
80-
76+
8177
expect(result).toBe(42);
8278
// Verify the act environment was restored
8379
expect(getIsReactActEnvironment()).toBe(previousEnvironment);

src/__tests__/wait-for.test.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,13 +337,13 @@ test.each([false, true])(
337337
test('waitFor throws clear error when switching from real timers to fake timers', async () => {
338338
jest.useRealTimers();
339339

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-
});
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+
});
345345

346-
await expect(waitForPromise).rejects.toThrow(
347-
'Changed from using real timers to fake timers while using waitFor',
348-
);
346+
await expect(waitForPromise).rejects.toThrow(
347+
'Changed from using real timers to fake timers while using waitFor',
348+
);
349349
});

0 commit comments

Comments
 (0)