import React from "react"; import cn from "classnames"; import { render } from "@testing-library/react"; import TextContainer from "../TextContainer"; describe("TextContainer", () => { it("should render as a div by default", () => { const { getByTestId } = render(); const container = getByTestId("container"); expect(container.tagName).toBe("DIV"); expect(getByTestId("container")).toMatchSnapshot(); }); it("should be able to render as a string component prop", () => { const component = "section"; const { getByTestId } = render( ); const container = getByTestId("container"); expect(container.tagName).toBe("SECTION"); expect(container).toMatchSnapshot(); }); it("should be able to render as a functional component", () => { const Component = ({ className, children }: any) => (
{children}
); const { getByTestId } = render( Hello, world! ); const container = getByTestId("container"); expect(container.tagName).toBe("SECTION"); expect(container).toMatchSnapshot(); }); it("should be able to render as a class component", () => { class Component extends React.Component { public render() { const { children, className } = this.props; return (
{children}
); } } const { getByTestId } = render( Hello, world! ); const container = getByTestId("container"); expect(container.tagName).toBe("SECTION"); expect(container).toMatchSnapshot(); }); it("should be able to use a children render function", () => { const { container } = render( {({ className }) => ( Content )} ); expect(container).toMatchSnapshot(); }); it("should default to the auto suffix for the rmd-text-container className", () => { const { getByTestId, rerender } = render( ); const container = getByTestId("container"); expect(container.className).toBe( "rmd-text-container rmd-text-container--auto" ); rerender(); expect(container.className).toBe( "rmd-text-container rmd-text-container--mobile" ); rerender(); expect(container.className).toBe( "rmd-text-container rmd-text-container--desktop" ); }); it("should correctly merge the prop className", () => { const { getByTestId } = render( ); const container = getByTestId("container"); expect(container.className).toBe( "rmd-text-container rmd-text-container--auto test-class-name" ); }); it("should be able to clone the class name into the child element", () => { const { getByText, rerender } = render(
Content
); expect(getByText("Content")).toHaveClass( "rmd-text-container rmd-text-container--auto" ); rerender(
Content
); expect(getByText("Content")).toHaveClass( "rmd-text-container rmd-text-container--auto custom" ); rerender(
Content
); expect(getByText("Content")).toHaveClass( "rmd-text-container rmd-text-container--auto custom div" ); }); });