Skip to content

Commit 7593128

Browse files
ihabadhamclaude
andcommitted
fix(tests): prevent async-retry timer leak in licenseFetcher tests
Add jest.clearAllTimers() and jest.useRealTimers() to afterEach to prevent "Cannot log after tests are done" errors caused by async-retry's internal setTimeout callbacks escaping the fake timer boundary. The issue occurred because async-retry schedules retries via setTimeout, and when jest.useRealTimers() was called, pending microtasks could fire after the test completed. See: jestjs/jest#10487 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 2ceb06f commit 7593128

1 file changed

Lines changed: 5 additions & 8 deletions

File tree

packages/react-on-rails-pro-node-renderer/tests/licenseFetcher.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ describe('LicenseFetcher', () => {
1616
});
1717

1818
afterEach(() => {
19+
// Clear any pending retry timers to prevent "Cannot log after tests are done" errors.
20+
// This is safe to call regardless of whether fake timers are active (no-op with real timers).
21+
// See: https://github.com/jestjs/jest/issues/10487
22+
jest.clearAllTimers();
23+
jest.useRealTimers();
1924
jest.restoreAllMocks();
2025
});
2126

@@ -117,8 +122,6 @@ describe('LicenseFetcher', () => {
117122
const result = await resultPromise;
118123

119124
expect(result).toBeNull();
120-
121-
jest.useRealTimers();
122125
});
123126

124127
it('uses custom API URL when set', async () => {
@@ -159,8 +162,6 @@ describe('LicenseFetcher', () => {
159162

160163
expect(result).toBeNull();
161164
expect(fetchSpy).toHaveBeenCalledTimes(3);
162-
163-
jest.useRealTimers();
164165
});
165166

166167
it('returns null on non-200 status after retries', async () => {
@@ -175,8 +176,6 @@ describe('LicenseFetcher', () => {
175176

176177
expect(result).toBeNull();
177178
expect(fetchSpy).toHaveBeenCalledTimes(3);
178-
179-
jest.useRealTimers();
180179
});
181180

182181
it('succeeds after retry', async () => {
@@ -199,8 +198,6 @@ describe('LicenseFetcher', () => {
199198

200199
expect(result).toEqual(mockResponse);
201200
expect(fetchSpy).toHaveBeenCalledTimes(2);
202-
203-
jest.useRealTimers();
204201
});
205202
});
206203
});

0 commit comments

Comments
 (0)