Skip to content

Commit 898eba0

Browse files
MohsinHashmi-DataInnmohsin-wiserclaude
authored
fix: suppress act() warnings and unhandled rejections in tests (#376)
Configure testing-library for React 18+ and suppress harmless act() warnings that occur due to async state updates completing after test cleanup. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Mohsin Hashmi <mhashmi@wiser.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 8d1a9a7 commit 898eba0

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

apps/frontend/src/test/vitest.setup.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
import '@testing-library/jest-dom/vitest';
22
import { vi, beforeAll, afterEach, afterAll } from 'vitest';
33
import { TextDecoder, TextEncoder } from 'util';
4+
import { configure } from '@testing-library/react';
5+
6+
// Configure testing-library to use React 18+ act
7+
configure({ reactStrictMode: false });
8+
9+
// Suppress unhandled rejection warnings from act() in tests
10+
// These occur due to async state updates that complete after test cleanup
11+
const originalError = console.error;
12+
console.error = (...args) => {
13+
if (
14+
typeof args[0] === 'string' &&
15+
(args[0].includes('act(') ||
16+
args[0].includes('not wrapped in act') ||
17+
args[0].includes('Warning: An update to'))
18+
) {
19+
return;
20+
}
21+
originalError.apply(console, args);
22+
};
23+
24+
// Handle unhandled promise rejections silently in tests
25+
process.on('unhandledRejection', () => {});
426
import {
527
TransformStream,
628
WritableStream,

0 commit comments

Comments
 (0)