Skip to content

Commit 356c30c

Browse files
committedApr 30, 2020
Exclude forward ref on deep mount
1 parent fd3b939 commit 356c30c

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed
 

‎src/mount.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import omitBy from 'lodash/omitBy';
22
import isNil from 'lodash/isNil';
3+
import {ForwardRef} from 'react-is';
34

45
import {typeName} from 'enzyme/build/Debug';
56
import {childrenOfNode, propsOfNode} from 'enzyme/build/RSTTraversal';
@@ -48,7 +49,10 @@ function internalNodeToJson(node, options) {
4849
return node.map(child => internalNodeToJson(child, options));
4950
}
5051

51-
if (options.mode === 'deep' && typeof node.type === 'function') {
52+
if (
53+
options.mode === 'deep' &&
54+
(typeof node.type === 'function' || node.type.$$typeof === ForwardRef)
55+
) {
5256
return internalNodeToJson(node.rendered, options);
5357
}
5458

‎tests/__snapshots__/mount-deep.test.js.snap

+17
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,23 @@ exports[`converts pure mount with mixed children 1`] = `
227227
</div>
228228
`;
229229

230+
exports[`excludes forwardRef node but renders wrapped component 1`] = `
231+
<div
232+
className="basic-class undefined"
233+
onClick={[Function]}
234+
>
235+
<div
236+
className="group"
237+
id="group-id"
238+
>
239+
<span />
240+
<span
241+
className="empty"
242+
/>
243+
</div>
244+
</div>
245+
`;
246+
230247
exports[`handles a component which returns null 1`] = `""`;
231248

232249
exports[`includes undefined props 1`] = `

‎tests/mount-deep.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
ClassWithNull,
2020
ClassArrayRender,
2121
} from './fixtures/class';
22+
import {ForwardRefWithDefaultProps} from './fixtures/forwardRef';
2223

2324
Enzyme.configure({adapter: new Adapter()});
2425
const deepOptions = {mode: 'deep'};
@@ -128,3 +129,9 @@ it('renders multiple elements as a result of find', () => {
128129

129130
expect(mountToJson(mounted.find('li'), deepOptions)).toMatchSnapshot();
130131
});
132+
133+
it('excludes forwardRef node but renders wrapped component', () => {
134+
const mounted = mount(<ForwardRefWithDefaultProps />);
135+
136+
expect(mountToJson(mounted, deepOptions)).toMatchSnapshot();
137+
});

0 commit comments

Comments
 (0)
Please sign in to comment.