mirror of
https://github.com/bendtherules/react-to-markdown.git
synced 2026-08-18 22:03:20 +00:00
renderer-spec - Add basic tests for literal and one level component
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
import * as React from "react";
|
||||||
|
import { render } from "../src/renderer";
|
||||||
|
|
||||||
|
test("should render plain text", () => {
|
||||||
|
expect((render("abcd") as string).trim()).toBe("abcd");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should render numbers as text", () => {
|
||||||
|
expect((render(123) as string).trim()).toBe("123");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should render null and not fail for empty values", () => {
|
||||||
|
expect(render(null)).toBe(null);
|
||||||
|
expect(render(undefined)).toBe(null);
|
||||||
|
expect(render([])).toBe(null);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should render plain text with simple Function Component", () => {
|
||||||
|
function TestComponent() {
|
||||||
|
return "abcd";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Note: Rendering string from JSX shows TS error (https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20544). This is a workaround.
|
||||||
|
expect(
|
||||||
|
(render(
|
||||||
|
React.createElement((TestComponent as unknown) as React.FunctionComponent)
|
||||||
|
) as string).trim()
|
||||||
|
).toBe("abcd");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("should render plain text with simple Class Component", () => {
|
||||||
|
class TestComponent extends React.Component {
|
||||||
|
render() {
|
||||||
|
return "abcd";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
expect((render(<TestComponent />) as string).trim()).toBe("abcd");
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user