Skip to content

Commit bf35298

Browse files
authored
feat: Children passed to a mocked component are now rendered as the children of the component.
Ability to render children
2 parents 9b53a2f + c2734f4 commit bf35298

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/happy-path.spec.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ it('should have the prop held', () => {
3030
expect(getByMockComponent(MockedComponent).props.value).toEqual('val');
3131
});
3232

33+
it('should render any passed children', () => {
34+
render(
35+
<div>
36+
<MockedComponent><button>Save</button></MockedComponent>
37+
</div>
38+
);
39+
40+
expect(screen.getByRole('button', {name: 'Save'})).toBeInTheDocument();
41+
});
42+
3343
it('should hold the last value on a re-render', () => {
3444
const {rerender} = render(<TestedComponent value='val' />);
3545
rerender(<TestedComponent value='new-val' />);

src/setupMockComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export function setupMockComponent<PropType>(mockedComponent: FC<PropType>, opti
4545
return React.createElement(type, {
4646
ref,
4747
'data-testid': mockElementTestId,
48-
});
48+
}, props.children);
4949
};
5050

5151
const comp = mockedComponent as MockedComponent<PropType>;

0 commit comments

Comments
 (0)