diff --git a/packages/component-test-utils-react/src/__tests__/shallow-html.spec.js b/packages/component-test-utils-react/src/__tests__/shallow-html.spec.js index 1eee52e..789a988 100644 --- a/packages/component-test-utils-react/src/__tests__/shallow-html.spec.js +++ b/packages/component-test-utils-react/src/__tests__/shallow-html.spec.js @@ -145,6 +145,24 @@ describe('shallow - html', () => { ); }); + it('should render component that with HOC and with mock', () => { + const Child = ({className}) => { + return ; + }; + + const withStyle = Component => () => { + return ; + }; + + const Component = withStyle(Child); + + const cmp = shallow(, {mocks: {Child: true}}); + + expect(cmp.html()).toBe( + '' + ); + }); + it('should render component that use useState hooks', () => { const Component = () => { const [nbLikes] = React.useState(0); diff --git a/packages/component-test-utils-react/src/render/render.js b/packages/component-test-utils-react/src/render/render.js index 5d0b164..07cdf1c 100644 --- a/packages/component-test-utils-react/src/render/render.js +++ b/packages/component-test-utils-react/src/render/render.js @@ -27,9 +27,12 @@ const render = (reactEl, config, ShallowRender) => { } if (!isAlreadyMocked && shouldBeRender(reactEl, config)) { + const mock = config.mocks && config.mocks[reactEl.type.displayName || reactEl.type.name]; + const el = mock === true ? reactEl.type : mock || reactEl.type; + const shallowRender = new ShallowRender( React.createElement( - (config.mocks && config.mocks[reactEl.type.displayName || reactEl.type.name]) || reactEl.type, + el, reactEl.props, reactEl.props && reactEl.props.children ),