Skip to content

Commit 1185eb2

Browse files
committed
Add tests for as component (failing typescript)
1 parent 27ea14d commit 1185eb2

File tree

2 files changed

+57
-12
lines changed

2 files changed

+57
-12
lines changed

src/ErrorMessage.test.tsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ describe('ErrorMessage', () => {
4545
expect(asFragment()).toMatchSnapshot();
4646
});
4747

48-
it('should render correctly with flat errors and as with component and render', () => {
48+
it('should render correctly with flat errors and as with element and render', () => {
4949
const { asFragment } = render(
5050
<ErrorMessage
5151
as={<span />}
@@ -58,7 +58,7 @@ describe('ErrorMessage', () => {
5858
expect(asFragment()).toMatchSnapshot();
5959
});
6060

61-
it('should render correctly with flat errors and as with component and className and render', () => {
61+
it('should render correctly with flat errors and as with element and className and render', () => {
6262
const { asFragment } = render(
6363
<ErrorMessage
6464
as={<span />}
@@ -72,6 +72,37 @@ describe('ErrorMessage', () => {
7272
expect(asFragment()).toMatchSnapshot();
7373
});
7474

75+
it('should render correctly with flat errors and as with component', () => {
76+
function CustErrComp({ children }: { children: React.ReactNode }) {
77+
return <div>{children}</div>;
78+
}
79+
const { asFragment } = render(
80+
<ErrorMessage
81+
as={CustErrComp}
82+
errors={{ flat: { type: 'flat', message: 'flat' } }}
83+
name="flat"
84+
/>,
85+
);
86+
87+
expect(asFragment()).toMatchSnapshot();
88+
});
89+
90+
it('should render correctly with flat errors and as with component and render', () => {
91+
function CustErrComp({ children }: { children: React.ReactNode }) {
92+
return <div>{children}</div>;
93+
}
94+
const { asFragment } = render(
95+
<ErrorMessage
96+
as={CustErrComp}
97+
errors={{ flat: { type: 'flat', message: 'flat' } }}
98+
name="flat"
99+
render={({ message }) => message}
100+
/>,
101+
);
102+
103+
expect(asFragment()).toMatchSnapshot();
104+
});
105+
75106
it('should render correctly with flat multiple errors and render', () => {
76107
const { asFragment } = render(
77108
<ErrorMessage
@@ -99,7 +130,7 @@ describe('ErrorMessage', () => {
99130
expect(asFragment()).toMatchSnapshot();
100131
});
101132

102-
it('should render correctly with flat multiple errors and as with component and render', () => {
133+
it('should render correctly with flat multiple errors and as with element and render', () => {
103134
const { asFragment } = render(
104135
<ErrorMessage
105136
as={<div />}
@@ -204,7 +235,7 @@ describe('ErrorMessage', () => {
204235
expect(asFragment()).toMatchSnapshot();
205236
});
206237

207-
it('should render correctly with nested multiple errors and as with component and render', () => {
238+
it('should render correctly with nested multiple errors and as with element and render', () => {
208239
const { asFragment } = render(
209240
<ErrorMessage
210241
as={<div />}
@@ -269,7 +300,7 @@ describe('ErrorMessage', () => {
269300
expect(asFragment()).toMatchSnapshot();
270301
});
271302

272-
it('should render correctly with nested errors array and as with component and render', () => {
303+
it('should render correctly with nested errors array and as with element and render', () => {
273304
const { asFragment } = render(
274305
<ErrorMessage
275306
as={<span />}
@@ -319,7 +350,7 @@ describe('ErrorMessage', () => {
319350
expect(asFragment()).toMatchSnapshot();
320351
});
321352

322-
it('should render correctly with nested multiple errors array and as with component and render', () => {
353+
it('should render correctly with nested multiple errors array and as with element and render', () => {
323354
const { asFragment } = render(
324355
<ErrorMessage
325356
as={<div />}

src/__snapshots__/ErrorMessage.test.tsx.snap

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ exports[`ErrorMessage should render correctly with flat errors 1`] = `
88
</DocumentFragment>
99
`;
1010

11-
exports[`ErrorMessage should render correctly with flat errors and as with component and className and render 1`] = `
11+
exports[`ErrorMessage should render correctly with flat errors and as with component 1`] = `
12+
<DocumentFragment>
13+
<div>
14+
flat
15+
</div>
16+
</DocumentFragment>
17+
`;
18+
19+
exports[`ErrorMessage should render correctly with flat errors and as with component and render 1`] = `
20+
<DocumentFragment>
21+
flat
22+
</DocumentFragment>
23+
`;
24+
25+
exports[`ErrorMessage should render correctly with flat errors and as with element and className and render 1`] = `
1226
<DocumentFragment>
1327
<span
1428
class="test"
@@ -18,7 +32,7 @@ exports[`ErrorMessage should render correctly with flat errors and as with compo
1832
</DocumentFragment>
1933
`;
2034

21-
exports[`ErrorMessage should render correctly with flat errors and as with component and render 1`] = `
35+
exports[`ErrorMessage should render correctly with flat errors and as with element and render 1`] = `
2236
<DocumentFragment>
2337
<span>
2438
flat
@@ -44,7 +58,7 @@ exports[`ErrorMessage should render correctly with flat errors and as with strin
4458
</DocumentFragment>
4559
`;
4660

47-
exports[`ErrorMessage should render correctly with flat multiple errors and as with component and render 1`] = `
61+
exports[`ErrorMessage should render correctly with flat multiple errors and as with element and render 1`] = `
4862
<DocumentFragment>
4963
<div>
5064
flat
@@ -86,7 +100,7 @@ exports[`ErrorMessage should render correctly with nested errors array 1`] = `
86100
</DocumentFragment>
87101
`;
88102

89-
exports[`ErrorMessage should render correctly with nested errors array and as with component and render 1`] = `
103+
exports[`ErrorMessage should render correctly with nested errors array and as with element and render 1`] = `
90104
<DocumentFragment>
91105
<span>
92106
array
@@ -116,7 +130,7 @@ exports[`ErrorMessage should render correctly with nested errors object and as w
116130
</DocumentFragment>
117131
`;
118132

119-
exports[`ErrorMessage should render correctly with nested multiple errors and as with component and render 1`] = `
133+
exports[`ErrorMessage should render correctly with nested multiple errors and as with element and render 1`] = `
120134
<DocumentFragment>
121135
<div>
122136
object
@@ -138,7 +152,7 @@ exports[`ErrorMessage should render correctly with nested multiple errors and re
138152
</DocumentFragment>
139153
`;
140154

141-
exports[`ErrorMessage should render correctly with nested multiple errors array and as with component and render 1`] = `
155+
exports[`ErrorMessage should render correctly with nested multiple errors array and as with element and render 1`] = `
142156
<DocumentFragment>
143157
<div>
144158
array

0 commit comments

Comments
 (0)