|
| 1 | +import CodeHighlighter from "../CodeHighlighter"; |
| 2 | +import { render, screen } from "@testing-library/react-native"; |
| 3 | +import { atomOneDarkReasonable as hljsStyle } from "react-syntax-highlighter/dist/esm/styles/hljs"; |
| 4 | + |
| 5 | +describe(CodeHighlighter, () => { |
| 6 | + it("render", async () => { |
| 7 | + const code = `const hello = "world"`; |
| 8 | + const r = await render( |
| 9 | + <CodeHighlighter hljsStyle={{}} language="typescript"> |
| 10 | + {code} |
| 11 | + </CodeHighlighter>, |
| 12 | + ); |
| 13 | + |
| 14 | + expect(screen.queryByTestId("react-native-code-highlighter")).toBeDefined(); |
| 15 | + expect(screen.getByText("const")).toBeDefined(); |
| 16 | + expect(screen.getByText("hello =")).toBeDefined(); |
| 17 | + expect(screen.getByText('"world"')).toBeDefined(); |
| 18 | + |
| 19 | + const tree = r.toJSON(); |
| 20 | + expect(tree).toMatchSnapshot(); |
| 21 | + }); |
| 22 | + it("render with styles", async () => { |
| 23 | + const code = ` |
| 24 | + const hello = "world"; |
| 25 | + let foo = "bar"; |
| 26 | + `; |
| 27 | + const r = await render( |
| 28 | + <CodeHighlighter |
| 29 | + hljsStyle={hljsStyle} |
| 30 | + containerStyle={{ padding: 8, backgroundColor: "#000" }} |
| 31 | + textStyle={{ color: "#fff", fontSize: 12 }} |
| 32 | + language="javascript" |
| 33 | + > |
| 34 | + {code} |
| 35 | + </CodeHighlighter>, |
| 36 | + ); |
| 37 | + |
| 38 | + expect(screen.queryByTestId("react-native-code-highlighter")).toBeDefined(); |
| 39 | + expect(screen.getByText("const")).toBeDefined(); |
| 40 | + expect(screen.getByText("hello =")).toBeDefined(); |
| 41 | + expect(screen.getByText('"world"')).toBeDefined(); |
| 42 | + expect(screen.getByText("let")).toBeDefined(); |
| 43 | + expect(screen.getByText("foo =")).toBeDefined(); |
| 44 | + expect(screen.getByText('"bar"')).toBeDefined(); |
| 45 | + |
| 46 | + const tree = r.toJSON(); |
| 47 | + expect(tree).toMatchSnapshot(); |
| 48 | + }); |
| 49 | +}); |
0 commit comments