Skip to content

Commit

Permalink
add test for insert node
Browse files Browse the repository at this point in the history
  • Loading branch information
sailist committed Feb 9, 2025
1 parent fac7c4f commit 5e98f15
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/query/insertNode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NodeToString } from "../../src/helper";
import { RangeEditor } from "../../src/editor";
import { test, expect } from "vitest";

test('insertAfter', () => {
const root = document.createElement("div")
root.innerHTML = "<p>hello</p>"
const editor = new RangeEditor(
{
},
root,
);

const src = document.createElement("b");
src.textContent = "hello";
editor._insertAfter(src, root.children[0]);
const rootStr = NodeToString(root);

expect(rootStr).toEqual("<div><p>hello</p><b>hello</b></div>");
});

test('insertBefore', () => {
const root = document.createElement("div")
root.innerHTML = "<p>hello</p>"
const editor = new RangeEditor(
{
},
root,
);

const src = document.createElement("b");
src.textContent = "hello";
editor._insertBefore(src, root.children[0]);
const rootStr = NodeToString(root);

expect(rootStr).toEqual("<div><b>hello</b><p>hello</p></div>");
});

0 comments on commit 5e98f15

Please sign in to comment.