test: kill act env warnings (globalThis flag + _notify act wrapper)

- setupTests.js: set globalThis.IS_REACT_ACT_ENVIRONMENT = true (RTL reads
  getGlobalThis, not global). Kills 'environment not configured for act'.
- _mock-db.js _notify: set flag true around subscriber cb, restore prev
  after. RTL waitFor flips flag false mid-poll -> act() warned. Now clean.
- 146 act warnings -> 0.
This commit is contained in:
david raistrick
2026-07-03 15:58:50 -04:00
parent 1a744e511a
commit 530aaadf90
4 changed files with 1185 additions and 6 deletions
+21
View File
@@ -1,5 +1,26 @@
// jest setup: RTL jest-dom + mock DB reset per test.
import '@testing-library/jest-dom';
// RTL v14: tell React this is an act environment. Without it every
// async update warns "current testing environment is not configured to
// support act(...)". RTL reads getGlobalThis(), so set on globalThis.
// Must be set before any component renders.
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
// WARNING = FAILURE. Fail test on any console.error/warn (React act warnings,
// deprecations, prop errors). App code's own error logs allowed only inside
// try/catch failure paths — those tests should assert the error was handled,
// not silently log it. Override the spies to throw.
const originalError = console.error;
const originalWarn = console.warn;
console.error = (...args) => {
originalError(...args);
throw new Error(`console.error in test: ${args.map(String).join(' ').slice(0, 500)}`);
};
console.warn = (...args) => {
originalWarn(...args);
throw new Error(`console.warn in test: ${args.map(String).join(' ').slice(0, 500)}`);
};
import { resetMockDb } from './__mocks__/firebase/_mock-db';
// polyfill crypto.randomUUID for jsdom (used by generateId in App.js).