Skip to content

Commit f300bd1

Browse files
author
Alice Koreman
committed
keep test util backwards compatible
1 parent e4c46c7 commit f300bd1

File tree

2 files changed

+13
-22
lines changed

2 files changed

+13
-22
lines changed

src/code-view/__tests__/code-view.test.tsx

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,21 @@ describe("CodeView", () => {
1616
test("correctly renders simple content", () => {
1717
render(<CodeView content={"Hello World"}></CodeView>);
1818
const wrapper = createWrapper()!.findCodeView();
19-
expect(wrapper!.findContent()[0].getElement()).toHaveTextContent("Hello World");
19+
expect(wrapper!.findContent().getElement()).toHaveTextContent("Hello World");
2020
});
2121

2222
test("correctly renders multi line content", () => {
2323
render(<CodeView content={`# Hello World\n\nThis is a markdown example.`}></CodeView>);
2424
const wrapper = createWrapper()!.findCodeView()!;
2525
const content = wrapper.findContent();
26-
expect(content[0].getElement()).toHaveTextContent("# Hello World");
27-
expect(content[1].getElement()).toHaveTextContent("");
28-
expect(content[2].getElement()).toHaveTextContent("This is a markdown example.");
26+
expect(content.getElement()).toHaveTextContent("# Hello World This is a markdown example.");
2927
});
3028

3129
test("correctly renders multi line content", () => {
32-
const content = `# Hello World\n\nThis is a markdown example.`;
33-
34-
render(<CodeView content={content}></CodeView>);
35-
const wrapper = createWrapper()!.findCodeView();
36-
const contentElements = wrapper!.findContent();
37-
expect(contentElements.length).toEqual(3);
38-
const renderedContent = contentElements
39-
.map((element) => element.getElement().textContent)
40-
.join("")
41-
.trim();
42-
expect(renderedContent).toBe(content);
30+
render(<CodeView content={`# Hello World\n\nThis is a markdown example.`}></CodeView>);
31+
const wrapper = createWrapper()!.findCodeView()!;
32+
const content = wrapper.findContent();
33+
expect(content.getElement()).toHaveTextContent("# Hello World This is a markdown example.");
4334
});
4435

4536
test("correctly renders copy button slot", () => {
@@ -84,13 +75,13 @@ describe("CodeView", () => {
8475
></CodeView>,
8576
);
8677
const wrapper = createWrapper().findCodeView()!;
87-
expect(wrapper!.findContent()[0].getElement().innerHTML).toContain("tokenized");
78+
expect(wrapper!.findContent().getElement().innerHTML).toContain("tokenized");
8879
});
8980

9081
test("correctly tokenizes content if highlight is set to language rules", () => {
9182
render(<CodeView content={'const hello: string = "world";'} highlight={typescriptHighlightRules}></CodeView>);
9283
const wrapper = createWrapper().findCodeView()!;
93-
const element = wrapper!.findContent()[0].getElement();
84+
const element = wrapper!.findContent().getElement();
9485

9586
// Check that the content is tokenized following typescript rules.
9687
expect(getByText(element, "const")).toHaveClass("ace_type");
@@ -102,21 +93,21 @@ describe("CodeView", () => {
10293
test("sets nowrap class to line if linesWrapping undefined", () => {
10394
render(<CodeView content={"Hello World"}></CodeView>);
10495
const wrapper = createWrapper().findCodeView()!;
105-
const element = wrapper!.findContent()[0].getElement();
96+
const element = wrapper!.findContent().getElement();
10697
expect(element.outerHTML).toContain("code-line-nowrap");
10798
});
10899

109100
test("sets nowrap class to line if linesWrapping false", () => {
110101
render(<CodeView lineWrapping={false} content={"Hello World"}></CodeView>);
111102
const wrapper = createWrapper().findCodeView()!;
112-
const element = wrapper!.findContent()[0].getElement();
103+
const element = wrapper!.findContent().getElement();
113104
expect(element.outerHTML).toContain("code-line-nowrap");
114105
});
115106

116107
test("sets wrap class to line if linesWrapping true", () => {
117108
render(<CodeView lineWrapping={true} content={"Hello World"}></CodeView>);
118109
const wrapper = createWrapper().findCodeView()!;
119-
const element = wrapper!.findContent()[0].getElement();
110+
const element = wrapper!.findContent().getElement();
120111
expect(element.outerHTML).toContain("code-line-wrap");
121112
});
122113
});

src/test-utils/dom/code-view/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import styles from "../../../code-view/styles.selectors.js";
77
export default class CodeViewWrapper extends ComponentWrapper {
88
static rootSelector: string = styles.root;
99

10-
findContent() {
11-
return this.findAllByClassName(styles["code-line"])!;
10+
findContent(): ElementWrapper {
11+
return this.find("tbody")!;
1212
}
1313

1414
findActions(): ElementWrapper | null {

0 commit comments

Comments
 (0)