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
+9 -1
View File
@@ -38,11 +38,16 @@ export const MOCK_DB = {
return () => state.subscribers.get(path)?.delete(cb);
},
_notify(path) {
// notify exact doc path subscribers (wrapped in act for test isolation)
// notify exact doc path subscribers (wrapped in act for test isolation).
// Set flag true around cb: RTL asyncWrapper (waitFor) flips it false
// during poll, making raw react act() warn 'not configured'.
if (state.subscribers.has(path)) state.subscribers.get(path).forEach(cb => {
try {
const { act } = require('react');
const prev = globalThis.IS_REACT_ACT_ENVIRONMENT;
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
act(() => cb());
globalThis.IS_REACT_ACT_ENVIRONMENT = prev;
} catch {
cb();
}
@@ -52,7 +57,10 @@ export const MOCK_DB = {
if (parent && state.subscribers.has(parent)) state.subscribers.get(parent).forEach(cb => {
try {
const { act } = require('react');
const prev = globalThis.IS_REACT_ACT_ENVIRONMENT;
globalThis.IS_REACT_ACT_ENVIRONMENT = true;
act(() => cb());
globalThis.IS_REACT_ACT_ENVIRONMENT = prev;
} catch {
cb();
}