diff --git a/src/edit.test.js b/src/edit.test.js index 3cbed9b..8c467d4 100644 --- a/src/edit.test.js +++ b/src/edit.test.js @@ -526,6 +526,13 @@ function createCitation({ }; } +// The mocked notices store is module-level state shared by every render in +// this file; reset it per test so a notice left by one test (and its Dismiss +// button) never leaks into another under --randomize. +beforeEach(() => { + require('@wordpress/data').__unstableResetNotices(); +}); + describe('Edit focus management', () => { beforeEach(() => { jest.clearAllMocks(); @@ -538,7 +545,6 @@ describe('Edit focus management', () => { downloadCslJsonExport.mockReset(); downloadRisExport.mockReset(); copyTextToClipboard.mockReset(); - require('@wordpress/data').__unstableResetNotices(); }); it('shows DOI/BibTeX-only guidance when parsing fails without entries', async () => { diff --git a/src/hooks/use-citation-editor-state.test.js b/src/hooks/use-citation-editor-state.test.js index 3b564ce..67b1c36 100644 --- a/src/hooks/use-citation-editor-state.test.js +++ b/src/hooks/use-citation-editor-state.test.js @@ -107,6 +107,10 @@ function makeHookArgs(citations = [makeCitation()]) { beforeEach(() => { jest.clearAllMocks(); + // mockReset (not just clearAllMocks) drops queued *Once values: several + // race tests queue a pending format result the save never reaches, which + // would otherwise be handed to whichever test calls the formatter next. + formatBibliographyEntries.mockReset(); formatBibliographyEntries.mockImplementation((items) => items.map(() => 'Reformatted entry') ); diff --git a/src/lib/parser.test.js b/src/lib/parser.test.js index 76a9ae4..28f7a62 100644 --- a/src/lib/parser.test.js +++ b/src/lib/parser.test.js @@ -25,6 +25,11 @@ import { } from './parser'; import { formatBibliographyEntries } from './formatting/csl'; +// parsePastedInput lazily imports './formatting/csl' at call time, so the +// module registry must keep resolving to these file-level mock instances. +const formattingCslMock = jest.requireMock('./formatting/csl'); +const apiFetchMock = jest.requireMock('@wordpress/api-fetch'); + describe('validateAndSanitizeCsl', () => { it('sanitizes nested values and normalizes issued date-parts', () => { const sanitized = validateAndSanitizeCsl({ @@ -1458,8 +1463,12 @@ describe('PMID fallback resolution', () => { } afterEach(() => { + // Undo mockParserDependencies: after resetModules the registry would + // hand parser's lazy import a fresh formatter mock the other tests in + // this file never see, and api-fetch would stay mocked as undefined. jest.resetModules(); - jest.dontMock('@wordpress/api-fetch'); + jest.doMock('./formatting/csl', () => formattingCslMock); + jest.doMock('@wordpress/api-fetch', () => apiFetchMock); }); it('falls back to window.fetch when the WordPress REST helper is unavailable', async () => {