Import text-editor code into the repository

This commit is contained in:
Andrey Antukh 2024-11-19 17:05:30 +01:00
parent 68397edd4d
commit 04a0d867b0
65 changed files with 11112 additions and 7 deletions

View file

@ -0,0 +1,26 @@
import { describe, test, expect } from 'vitest';
import { isTextNode, getTextNodeLength } from './TextNode';
import { createLineBreak } from './LineBreak';
/* @vitest-environment jsdom */
describe("TextNode", () => {
test("isTextNode should return true when the passed node is a Text", () => {
expect(isTextNode(new Text("Hello, World!"))).toBe(true);
expect(isTextNode(Infinity)).toBe(false);
expect(isTextNode(true)).toBe(false);
expect(isTextNode("hola")).toBe(false);
expect(isTextNode({})).toBe(false);
expect(isTextNode([])).toBe(false);
expect(() => isTextNode(undefined)).toThrowError('Invalid text node');
expect(() => isTextNode(null)).toThrowError('Invalid text node');
expect(() => isTextNode(0)).toThrowError('Invalid text node');
});
test("getTextNodeLength should return the length of the text node or 0 if it is a <br>", () => {
expect(getTextNodeLength(new Text("Hello, World!"))).toBe(13);
expect(getTextNodeLength(createLineBreak())).toBe(0);
expect(() => getTextNodeLength(undefined)).toThrowError('Invalid text node');
expect(() => getTextNodeLength(null)).toThrowError('Invalid text node');
expect(() => getTextNodeLength(0)).toThrowError('Invalid text node');
});
});