Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adriantoine/enzyme-to-json
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.4.4
Choose a base ref
...
head repository: adriantoine/enzyme-to-json
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.5.0
Choose a head ref
  • 3 commits
  • 4 files changed
  • 3 contributors

Commits on Apr 30, 2020

  1. Copy the full SHA
    356c30c View commit details

Commits on May 26, 2020

  1. Merge pull request #167 from mmarcuccio/mount-deep-exclude-forward-ref

    Exclude forward ref when using deep mount
    VincentLanglet authored May 26, 2020
    Copy the full SHA
    866547a View commit details
  2. v3.5.0

    VincentLanglet committed May 26, 2020
    Copy the full SHA
    c62fd3c View commit details
Showing with 30 additions and 2 deletions.
  1. +1 −1 package.json
  2. +5 −1 src/mount.js
  3. +17 −0 tests/__snapshots__/mount-deep.test.js.snap
  4. +7 −0 tests/mount-deep.test.js
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.4.4",
"version": "3.5.0",
"name": "enzyme-to-json",
"description": "convert enzyme wrapper to a format compatible with Jest snapshot",
"main": "index.js",
6 changes: 5 additions & 1 deletion src/mount.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import omitBy from 'lodash/omitBy';
import isNil from 'lodash/isNil';
import {ForwardRef} from 'react-is';

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

if (options.mode === 'deep' && typeof node.type === 'function') {
if (
options.mode === 'deep' &&
(typeof node.type === 'function' || node.type.$$typeof === ForwardRef)
) {
return internalNodeToJson(node.rendered, options);
}

17 changes: 17 additions & 0 deletions tests/__snapshots__/mount-deep.test.js.snap
Original file line number Diff line number Diff line change
@@ -227,6 +227,23 @@ exports[`converts pure mount with mixed children 1`] = `
</div>
`;

exports[`excludes forwardRef node but renders wrapped component 1`] = `
<div
className="basic-class undefined"
onClick={[Function]}
>
<div
className="group"
id="group-id"
>
<span />
<span
className="empty"
/>
</div>
</div>
`;

exports[`handles a component which returns null 1`] = `""`;

exports[`includes undefined props 1`] = `
7 changes: 7 additions & 0 deletions tests/mount-deep.test.js
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import {
ClassWithNull,
ClassArrayRender,
} from './fixtures/class';
import {ForwardRefWithDefaultProps} from './fixtures/forwardRef';

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

expect(mountToJson(mounted.find('li'), deepOptions)).toMatchSnapshot();
});

it('excludes forwardRef node but renders wrapped component', () => {
const mounted = mount(<ForwardRefWithDefaultProps />);

expect(mountToJson(mounted, deepOptions)).toMatchSnapshot();
});