Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/edit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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 () => {
Expand Down
4 changes: 4 additions & 0 deletions src/hooks/use-citation-editor-state.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
Expand Down
11 changes: 10 additions & 1 deletion src/lib/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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 () => {
Expand Down
Loading