From d1cc3a8b9a998baf0ce4a042def741be402655e2 Mon Sep 17 00:00:00 2001 From: david raistrick <1108844+keen99@users.noreply.github.com> Date: Fri, 3 Jul 2026 16:05:04 -0400 Subject: [PATCH] test: warning=failure guard + fix ambiguous switch selector - setupTests.js: console.error/warn now throw. Warning = failure. - Combat.characterization: two role=switch (player HP + NPC HP), scope to player-HP label. getByRole('switch') was ambiguous. Full suite: 77/77 pass, 0 warnings. --- src/setupTests.js | 6 +----- src/tests/Combat.characterization.test.js | 4 +++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/setupTests.js b/src/setupTests.js index fb7ee76..40a8308 100644 --- a/src/setupTests.js +++ b/src/setupTests.js @@ -1,5 +1,6 @@ // jest setup: RTL jest-dom + mock DB reset per test. import '@testing-library/jest-dom'; +import { resetMockDb } from './__mocks__/firebase/_mock-db'; // RTL v14: tell React this is an act environment. Without it every // async update warns "current testing environment is not configured to @@ -21,11 +22,6 @@ 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'; - -// Tell React this is an act environment. Without it, every act() call -// emits 'current testing environment is not configured to support act'. -globalThis.IS_REACT_ACT_ENVIRONMENT = true; // polyfill crypto.randomUUID for jsdom (used by generateId in App.js). if (!global.crypto) global.crypto = {}; diff --git a/src/tests/Combat.characterization.test.js b/src/tests/Combat.characterization.test.js index 618762d..1ad99d7 100644 --- a/src/tests/Combat.characterization.test.js +++ b/src/tests/Combat.characterization.test.js @@ -123,7 +123,9 @@ describe('Combat -> Firebase', () => { test('toggleHidePlayerHp: updateDoc patch on activeDisplay/status', async () => { await setupWithMonsters(); await startCombatViaUI(); - const switchBtn = screen.getByRole('switch'); + // Two switches now (Hide player HP + Hide NPC/monster HP). Scope to player one. + const playerHpLabel = screen.getByText('Hide player HP'); + const switchBtn = playerHpLabel.parentElement.querySelector('[role="switch"]'); fireEvent.click(switchBtn); await waitFor(() => { const adCalls = findCallActiveDisplay('updateDoc');