Skip to content

Commit 25c2604

Browse files
nperez0111claude
andcommitted
test(core): destroy editors in IndexingPlugin.test afterEach
The tests created BlockNoteEditor instances via createEditor() but never destroyed them. prosemirror-view's DOMObserver keeps a setTimeout alive waiting to flush pending mutations; when vitest tears down jsdom between test files the timer fires against a torn-down document and throws `ReferenceError: document is not defined`. Vitest catches it as an unhandled error and fails the whole run even when all 16 assertions pass. Local runs usually hit the lucky teardown ordering and pass; CI surfaces the race intermittently. Tracking created editors and calling _tiptapEditor.destroy() in afterEach ensures the DOMObserver timers are canceled before jsdom goes away. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent aefa9d2 commit 25c2604

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

packages/core/src/blocks/ListItem/NumberedListItem/IndexingPlugin.test.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Selection } from "prosemirror-state";
2-
import { describe, expect, it } from "vitest";
2+
import { afterEach, describe, expect, it } from "vitest";
33

44
import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
55

@@ -9,9 +9,22 @@ import { BlockNoteEditor } from "../../../editor/BlockNoteEditor.js";
99

1010
const PLUGIN_KEY = "numbered-list-indexing-decorations$";
1111

12+
// Track editors created in each test so we can destroy them in afterEach —
13+
// otherwise prosemirror-view's DOMObserver leaves a setTimeout alive that
14+
// fires after vitest tears down jsdom, throwing
15+
// `ReferenceError: document is not defined` and failing the run.
16+
const activeEditors: BlockNoteEditor<any, any, any>[] = [];
17+
18+
afterEach(() => {
19+
while (activeEditors.length) {
20+
activeEditors.pop()!._tiptapEditor.destroy();
21+
}
22+
});
23+
1224
function createEditor() {
1325
const editor = BlockNoteEditor.create();
1426
editor.mount(document.createElement("div"));
27+
activeEditors.push(editor);
1528
return editor;
1629
}
1730

0 commit comments

Comments
 (0)