diff --git a/src/code-view/__tests__/code-view.test.tsx b/src/code-view/__tests__/code-view.test.tsx index 0f2bd8e..52a4b47 100644 --- a/src/code-view/__tests__/code-view.test.tsx +++ b/src/code-view/__tests__/code-view.test.tsx @@ -3,7 +3,7 @@ import { cleanup, getByText, render } from "@testing-library/react"; import { afterEach, describe, expect, test } from "vitest"; -import CodeView from "../../../lib/components/code-view"; +import CodeView, { CodeViewProps } from "../../../lib/components/code-view"; import typescriptHighlightRules from "../../../lib/components/code-view/highlight/typescript"; import createWrapper from "../../../lib/components/test-utils/dom"; @@ -103,4 +103,11 @@ describe("CodeView", () => { const element = wrapper!.findContent().getElement(); expect(element.outerHTML).toContain("code-line-wrap"); }); + + test("handles undefined content", () => { + const props = {} as CodeViewProps; + render(); + const wrapper = createWrapper().findCodeView()!; + expect(wrapper!.findContent().getElement().textContent).toBe("\n"); + }); }); diff --git a/src/code-view/internal.tsx b/src/code-view/internal.tsx index 34507ce..f7d2698 100644 --- a/src/code-view/internal.tsx +++ b/src/code-view/internal.tsx @@ -32,7 +32,7 @@ const textHighlight = (code: string) => { }; export function InternalCodeView({ - content, + content = "", actions, lineNumbers, wrapLines,