Skip to content

Commit

Permalink
🐛 fix mocks true on white list mode
Browse files Browse the repository at this point in the history
  • Loading branch information
FBerthelot committed Jul 27, 2019
1 parent c744b2b commit 2ea5dc1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,24 @@ describe('shallow - html', () => {
);
});

it('should render component that with HOC and with mock', () => {
const Child = ({className}) => {
return <button type="button" className={className}>0 Like</button>;
};

const withStyle = Component => () => {
return <Component className="class-for-button"/>;
};

const Component = withStyle(Child);

const cmp = shallow(<Component/>, {mocks: {Child: true}});

expect(cmp.html()).toBe(
'<Child class="class-for-button"><button type="button" class="class-for-button">0 Like</button></Child>'
);
});

it('should render component that use useState hooks', () => {
const Component = () => {
const [nbLikes] = React.useState(0);
Expand Down
5 changes: 4 additions & 1 deletion packages/component-test-utils-react/src/render/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
Expand Down

0 comments on commit 2ea5dc1

Please sign in to comment.