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
20 changes: 19 additions & 1 deletion packages/core/src/editor/BlockNoteEditor.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { expect, it } from "vitest";
import { afterEach, expect, it } from "vitest";
import * as Y from "yjs";

import {
Expand All @@ -11,15 +11,27 @@ import { BlocksChanged } from "../api/getBlocksChangedByTransaction.js";
/**
* @vitest-environment jsdom
*/

const editorsToCleanup: BlockNoteEditor<any, any, any>[] = [];

afterEach(() => {
for (const editor of editorsToCleanup) {
editor.unmount();
}
editorsToCleanup.length = 0;
});

it("creates an editor", () => {
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
const posInfo = editor.transact((tr) => getNearestBlockPos(tr.doc, 2));
const info = getBlockInfo(posInfo);
expect(info.blockNoteType).toEqual("paragraph");
});

it("immediately replaces doc", async () => {
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
const blocks = await editor.tryParseMarkdownToBlocks(
"This is a normal text\n\n# And this is a large heading",
);
Expand Down Expand Up @@ -70,6 +82,7 @@ it("adds id attribute when requested", async () => {
const editor = BlockNoteEditor.create({
setIdAttribute: true,
});
editorsToCleanup.push(editor);
const blocks = await editor.tryParseMarkdownToBlocks(
"This is a normal text\n\n# And this is a large heading",
);
Expand All @@ -81,6 +94,7 @@ it("adds id attribute when requested", async () => {

it("updates block", () => {
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
editor.updateBlock(editor.document[0], {
content: "hello",
});
Expand All @@ -89,6 +103,7 @@ it("updates block", () => {
it("block prop types", () => {
// this test checks whether the block props are correctly typed in typescript
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
const block = editor.document[0];
if (block.type === "paragraph") {
// @ts-expect-error
Expand All @@ -108,6 +123,7 @@ it("block prop types", () => {

it("onMount and onUnmount", async () => {
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
let mounted = false;
let unmounted = false;
editor.onMount(() => {
Expand Down Expand Up @@ -143,6 +159,7 @@ it("sets an initial block id when using Y.js", async () => {
},
},
});
editorsToCleanup.push(editor);

editor.mount(document.createElement("div"));

Expand Down Expand Up @@ -193,6 +210,7 @@ it("sets an initial block id when using Y.js", async () => {

it("onBeforeChange", () => {
const editor = BlockNoteEditor.create();
editorsToCleanup.push(editor);
let beforeChangeCalled = false;
let changes: BlocksChanged<any, any, any> = [];
editor.onBeforeChange(({ getChanges }) => {
Expand Down
Loading