Skip to content

Commit d83436b

Browse files
committed
test: Fix re-rendering when a rendererWithFoo function is used
1 parent d09cf63 commit d83436b

File tree

1 file changed

+31
-32
lines changed

1 file changed

+31
-32
lines changed

src/web/testing/Render.tsx

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -118,38 +118,37 @@ export const rendererWith = ({
118118
};
119119
};
120120

121-
export const rendererWithTable = (options: RendererOptions = {}) => {
122-
const {render, ...other} = rendererWith(options);
123-
return {
124-
...other,
125-
render: (element: React.ReactNode) =>
126-
render(
127-
<table>
128-
<tbody>{element}</tbody>
129-
</table>,
130-
),
121+
export const rendererWithComponent =
122+
(Component: React.ComponentType<{children: React.ReactNode}>) =>
123+
(options: RendererOptions = {}) => {
124+
const {render, ...other} = rendererWith(options);
125+
return {
126+
...other,
127+
render: (element: React.ReactNode) => {
128+
const {rerender, ...rest} = render(<Component>{element}</Component>);
129+
return {
130+
rerender: (updatedElement: React.ReactNode) =>
131+
rerender(<Component>{updatedElement}</Component>),
132+
...rest,
133+
};
134+
},
135+
};
131136
};
132-
};
133137

134-
export const rendererWithTableRow = (options: RendererOptions = {}) => {
135-
const {render, ...other} = rendererWith(options);
136-
return {
137-
...other,
138-
render: (element: React.ReactNode) =>
139-
render(
140-
<table>
141-
<tbody>
142-
<tr>{element}</tr>
143-
</tbody>
144-
</table>,
145-
),
146-
};
147-
};
138+
export const rendererWithTable = rendererWithComponent(({children}) => (
139+
<table>
140+
<tbody>{children}</tbody>
141+
</table>
142+
));
148143

149-
export const rendererWithTableFooter = (options: RendererOptions = {}) => {
150-
const {render, ...other} = rendererWith(options);
151-
return {
152-
...other,
153-
render: (element: React.ReactNode) => render(<table>{element}</table>),
154-
};
155-
};
144+
export const rendererWithTableRow = rendererWithComponent(({children}) => (
145+
<table>
146+
<tbody>
147+
<tr>{children}</tr>
148+
</tbody>
149+
</table>
150+
));
151+
152+
export const rendererWithTableFooter = rendererWithComponent(({children}) => (
153+
<table>{children}</table>
154+
));

0 commit comments

Comments
 (0)