Skip to content

Commit e1f0615

Browse files
committed
fix: update render-rich-text tests
Returning array seems to work fine with react and add less wrappers
1 parent f7c7d92 commit e1f0615

2 files changed

Lines changed: 107 additions & 12 deletions

File tree

cmp/compiler/src/react/shared/__snapshots__/render-rich-text.test.tsx.snap

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,86 @@
11
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
22

3+
exports[`renderRichText > should handle nested components inside component tags 1`] = `
4+
[
5+
"You have ",
6+
<React.Fragment>
7+
<strong>
8+
10
9+
</strong>
10+
</React.Fragment>,
11+
" items",
12+
]
13+
`;
14+
15+
exports[`renderRichText > should handle the page.tsx example case 1`] = `
16+
[
17+
"Looking for a starting points or more instructions? Head over to ",
18+
<React.Fragment>
19+
<a
20+
className="font-medium"
21+
href="https://vercel.com/templates"
22+
>
23+
Templates
24+
</a>
25+
</React.Fragment>,
26+
" or the ",
27+
<React.Fragment>
28+
<a
29+
className="font-medium"
30+
href="https://nextjs.org/learn"
31+
>
32+
Learning
33+
</a>
34+
</React.Fragment>,
35+
" center.",
36+
]
37+
`;
38+
39+
exports[`renderRichText > should handle whitespace around component tags 1`] = `
40+
[
41+
"Looking for help? Head over to ",
42+
<React.Fragment>
43+
<a>
44+
Templates
45+
</a>
46+
</React.Fragment>,
47+
" or the ",
48+
<React.Fragment>
49+
<a>
50+
Learning
51+
</a>
52+
</React.Fragment>,
53+
" center.",
54+
]
55+
`;
56+
57+
exports[`renderRichText > should render complex mixed content with variables and components 1`] = `
58+
[
59+
"Hello ",
60+
"Alice",
61+
", you have ",
62+
<React.Fragment>
63+
<strong>
64+
5
65+
</strong>
66+
</React.Fragment>,
67+
" messages",
68+
]
69+
`;
70+
71+
exports[`renderRichText > should render component placeholders with JSX 1`] = `
72+
[
73+
"Click ",
74+
<React.Fragment>
75+
<a
76+
href="/home"
77+
>
78+
here
79+
</a>
80+
</React.Fragment>,
81+
]
82+
`;
83+
384
exports[`renderRichText > should render fragments with expressions 1`] = `
485
[
586
"Content that has text and other tags inside will br translated as a single entity: ",
@@ -21,6 +102,27 @@ exports[`renderRichText > should render fragments with expressions 1`] = `
21102
]
22103
`;
23104

105+
exports[`renderRichText > should render multiple same-type components 1`] = `
106+
[
107+
"Click ",
108+
<React.Fragment>
109+
<a
110+
href="/home"
111+
>
112+
here
113+
</a>
114+
</React.Fragment>,
115+
" or ",
116+
<React.Fragment>
117+
<a
118+
href="/about"
119+
>
120+
there
121+
</a>
122+
</React.Fragment>,
123+
]
124+
`;
125+
24126
exports[`renderRichText > should render untranslatable content as is 1`] = `
25127
[
26128
"Install using ",

cmp/compiler/src/react/shared/render-rich-text.test.tsx

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ describe("renderRichText", () => {
2929
a0: (chunks) => <a href="/home">{chunks}</a>,
3030
});
3131

32-
// Should return React elements, not a string
33-
expect(typeof result).not.toBe("string");
34-
expect(React.isValidElement(result)).toBe(true);
32+
expect(result).toMatchSnapshot();
3533
});
3634

3735
it("should render complex mixed content with variables and components", () => {
@@ -44,8 +42,7 @@ describe("renderRichText", () => {
4442
},
4543
);
4644

47-
expect(typeof result).not.toBe("string");
48-
expect(React.isValidElement(result)).toBe(true);
45+
expect(result).toMatchSnapshot();
4946
});
5047

5148
it("should render multiple same-type components", () => {
@@ -54,8 +51,7 @@ describe("renderRichText", () => {
5451
a1: (chunks) => <a href="/about">{chunks}</a>,
5552
});
5653

57-
expect(typeof result).not.toBe("string");
58-
expect(React.isValidElement(result)).toBe(true);
54+
expect(result).toMatchSnapshot();
5955
});
6056

6157
it("should handle the page.tsx example case", () => {
@@ -75,9 +71,7 @@ describe("renderRichText", () => {
7571
},
7672
);
7773

78-
// Should be React element, not string
79-
expect(typeof result).not.toBe("string");
80-
expect(React.isValidElement(result)).toBe(true);
74+
expect(result).toMatchSnapshot();
8175
});
8276

8377
it("should handle nested components inside component tags", () => {
@@ -86,7 +80,7 @@ describe("renderRichText", () => {
8680
strong0: (chunks) => <strong>{chunks}</strong>,
8781
});
8882

89-
expect(React.isValidElement(result)).toBe(true);
83+
expect(result).toMatchSnapshot();
9084
});
9185

9286
it("should handle whitespace around component tags", () => {
@@ -98,7 +92,6 @@ describe("renderRichText", () => {
9892
},
9993
);
10094

101-
expect(React.isValidElement(result)).toBe(true);
10295
expect(result).toMatchSnapshot();
10396
});
10497

0 commit comments

Comments
 (0)