Skip to content

Commit

Permalink
test(react-rich-text-lexical-renderer): use fake timers to run queueM…
Browse files Browse the repository at this point in the history
…icroTask
  • Loading branch information
Pavel910 committed Jul 25, 2024
1 parent b773167 commit ac47eae
Showing 1 changed file with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,45 +15,55 @@ import { emptyEditorContent, LexicalCmsInputRender } from "./lexical-render";
import theme from "./theme";
import { RichTextLexicalRenderer } from "~/index";

// Need to use fake timers because of internal use of `queueMicroTask`
jest.useFakeTimers();

describe("Test Rich Lexical Renderer", () => {
it("Paragraph string value type is rendered", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={defaultParagraphValue} />);
jest.runAllTimers();

// ASSERT
expect(container.innerHTML).toContain(expectedParagraphRenderedValue);
});

it("Header object value type is rendered", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={defaultHeadingValue} />);
jest.runAllTimers();
// ASSERT
expect(container.innerHTML).toContain(expectedHeadingRenderedValue);
});

it("Handle null as value", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={null} />);
jest.runAllTimers();
// ASSERT
expect(container.innerHTML).toEqual(emptyEditorContent);
});

it("Handle undefined as value", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={undefined} />);
jest.runAllTimers();
// ASSERT
expect(container.innerHTML).toEqual(emptyEditorContent);
});

it("Handle wrong lexical value", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={notCorrectValue} />);
jest.runAllTimers();
// ASSERT
expect(container.innerHTML).toEqual(emptyEditorContent);
});

it("Lexical CMS input includes title, paragraph, list and quote", async () => {
// ARRANGE
const { container } = render(<RichTextLexicalRenderer value={LexicalJsonCmsDataInput} />);
jest.runAllTimers();
// ASSERT
expect(container.innerHTML).toEqual(LexicalCmsInputRender);
});
Expand All @@ -63,6 +73,7 @@ describe("Test Rich Lexical Renderer", () => {
const { container } = render(
<RichTextLexicalRenderer value={LexicalJsonCmsDataInput} theme={theme} />
);
jest.runAllTimers();
// ASSERT
// editor is here
expect(container.innerHTML.includes("editor")).toBeTruthy();
Expand Down

0 comments on commit ac47eae

Please sign in to comment.