test: upgrade @testing-library/react v14, kill act warnings
@testing-library/react v13 -> v14. v13 used deprecated ReactDOMTestUtils.act on every render -> 708 deprecation warnings. v14 imports act from react directly. Drops to 0. Mock _notify (src/__mocks__/firebase/_mock-db.js): wrap subscriber callbacks in act(() => cb()). Sync setState from subscribe callbacks fired outside test act boundary -> 14 warnings. Now 0. try/catch fallback if react/act unavailable (defensive). Full suite: 166 pass / 1 fail (Combat.scenario BUG-11 pre-existing crash). Warnings: 1416 -> 0. Note: NOT complete kill-shared. App.js still inlines 8 logic fns (startEncounter, nextTurn, togglePause, endEncounter, addParticipant, updateParticipant, reorder/drag). turn.js versions dead in app, used by replay + turn tests only. Next: make handlers call turn.js.
This commit is contained in:
@@ -38,11 +38,25 @@ export const MOCK_DB = {
|
||||
return () => state.subscribers.get(path)?.delete(cb);
|
||||
},
|
||||
_notify(path) {
|
||||
// notify exact doc path subscribers
|
||||
if (state.subscribers.has(path)) state.subscribers.get(path).forEach(cb => cb());
|
||||
// notify exact doc path subscribers (wrapped in act for test isolation)
|
||||
if (state.subscribers.has(path)) state.subscribers.get(path).forEach(cb => {
|
||||
try {
|
||||
const { act } = require('react');
|
||||
act(() => cb());
|
||||
} catch {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
// notify parent collection subscribers
|
||||
const parent = path.split('/').slice(0, -1).join('/');
|
||||
if (parent && state.subscribers.has(parent)) state.subscribers.get(parent).forEach(cb => cb());
|
||||
if (parent && state.subscribers.has(parent)) state.subscribers.get(parent).forEach(cb => {
|
||||
try {
|
||||
const { act } = require('react');
|
||||
act(() => cb());
|
||||
} catch {
|
||||
cb();
|
||||
}
|
||||
});
|
||||
},
|
||||
nextId() { state.counter += 1; return String(state.counter).padStart(3, '0'); },
|
||||
_state: state,
|
||||
|
||||
Reference in New Issue
Block a user