Skip to content

Commit 81cb3df

Browse files
committed
test: restore document spies before each test
Move document spies into beforeEach where needed so they are recreated after restoreMocks resets them between tests. This keeps the tests compatible with the shared test infrastructure without changing their behavior.
1 parent f71d9dd commit 81cb3df

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

js/__tests__/toolbar-ui.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ const createMockElement = id => ({
5858
});
5959

6060
document.getElementById = jest.fn(createMockElement);
61-
jest.spyOn(document, "addEventListener").mockImplementation(() => {});
62-
jest.spyOn(document, "removeEventListener").mockImplementation(() => {});
6361
global.docById = id => document.getElementById(id);
6462

6563
describe("ToolbarUI - Visual Helpers", () => {
@@ -169,6 +167,10 @@ describe("ToolbarUI - Visual Helpers", () => {
169167
});
170168

171169
describe("FocusCycleManager - dispose", () => {
170+
beforeEach(() => {
171+
jest.spyOn(document, "addEventListener").mockImplementation(() => {});
172+
jest.spyOn(document, "removeEventListener").mockImplementation(() => {});
173+
});
172174
test("dispose removes all document-level event listeners", () => {
173175
const { FocusCycleManager } = require("../toolbar-ui");
174176
const manager = new FocusCycleManager();

js/widgets/__tests__/pitchstaircase.test.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,6 @@ window.widgetWindows = {
6060
})
6161
};
6262

63-
if (typeof document !== "undefined") {
64-
jest.spyOn(document, "getElementsByClassName").mockImplementation(() => {
65-
return [
66-
{
67-
style: {}
68-
}
69-
];
70-
});
71-
}
72-
7363
describe("PitchStaircase Widget", () => {
7464
let psc;
7565

@@ -285,6 +275,12 @@ describe("PitchStaircase Widget", () => {
285275
dict: {}
286276
}
287277
};
278+
279+
if (typeof document !== "undefined") {
280+
jest.spyOn(document, "getElementsByClassName").mockImplementation(() => [
281+
{ style: {} }
282+
]);
283+
}
288284
});
289285

290286
test("should set master volume to PREVIEWVOLUME and clear/show widget window on init", () => {

0 commit comments

Comments
 (0)