Skip to content

Commit 0457c81

Browse files
ryansolidClaude via Cursor
andcommitted
test(web): remove the stylesheet gate spec's document listeners between tests
Each test evaluates the stream helpers, which install their capture-phase listener on the shared jsdom document. Record and remove them so a test only sees listeners its own scripts added, which is what the count-once test means to exercise. Co-authored-by: Claude via Cursor <[email protected]>
1 parent c0d6c6c commit 0457c81

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

‎packages/web/test/runtime/stylesheet-gate.spec.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,25 @@ function apply(container, html) {
6868

6969
describe("streamed fragment stylesheet gate", () => {
7070
let container;
71+
let listeners;
7172

7273
beforeEach(() => {
7374
globalThis._$HY = { r: {}, fe() {} };
7475
container = document.createElement("div");
7576
document.body.appendChild(container);
77+
// The helpers install their gate listener on the shared jsdom document;
78+
// record each one so a test only sees the listeners its own scripts added.
79+
listeners = [];
80+
const add = document.addEventListener.bind(document);
81+
vi.spyOn(document, "addEventListener").mockImplementation((...args) => {
82+
listeners.push(args);
83+
add(...args);
84+
});
7685
});
7786

7887
afterEach(() => {
88+
vi.restoreAllMocks();
89+
for (const args of listeners) document.removeEventListener(...args);
7990
container.remove();
8091
delete globalThis._$HY;
8192
});

0 commit comments

Comments
 (0)