Skip to content
Merged
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
18 changes: 18 additions & 0 deletions frontend/src/__tests__/recommendations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,24 @@ import * as api from '../api';
import * as state from '../state';
import * as recsApi from '../api/recommendations';

// Issue #803: setup.ts's jest.clearAllMocks() clears recorded calls but keeps
// any mockReturnValue / mockResolvedValue / mockImplementation a test
// installed, so an override (cost period, column filters, selection, user,
// account overrides, ...) leaked into whichever test jest ran next and the
// file failed under --randomize. Snapshot every module mock's factory default
// once, and restore it before each test, so each test starts from the
// defaults above whatever order the tests run in.
const mockFactoryDefaults = [...[api, state, recsApi].flatMap((mod) => Object.values(mod)), mockShowToast]
.filter((fn): fn is jest.Mock => jest.isMockFunction(fn))
.map((fn) => [fn, fn.getMockImplementation()] as const);

beforeEach(() => {
for (const [fn, factoryDefault] of mockFactoryDefaults) {
fn.mockReset();
if (factoryDefault) fn.mockImplementation(factoryDefault);
}
});

describe('Recommendations Module', () => {
beforeEach(() => {
// Reset DOM
Expand Down
Loading