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.5.0
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.6.0
Choose a head ref
  • 6 commits
  • 6 files changed
  • 4 contributors

Commits on Aug 7, 2020

  1. Update package.json

    older versions of babel brings lodash vulnerabilities
    RamyaPayyavula authored Aug 7, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1ce6532 View commit details

Commits on Aug 9, 2020

  1. Merge pull request #170 from RamyaPayyavula/patch-2

    Update package.json
    VincentLanglet authored Aug 9, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    a4f83d3 View commit details

Commits on Sep 25, 2020

  1. Copy the full SHA
    a149fb0 View commit details
  2. remove only

    nathanmarks committed Sep 25, 2020
    Copy the full SHA
    33a39f0 View commit details

Commits on Sep 27, 2020

  1. Merge pull request #171 from nathanmarks/add-memo-support

    handle deep mounted memo components properly
    VincentLanglet authored Sep 27, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6d326a5 View commit details
  2. v3.6.0

    VincentLanglet committed Sep 27, 2020
    Copy the full SHA
    6e8c591 View commit details
Showing with 292 additions and 5 deletions.
  1. +2 −2 package.json
  2. +9 −2 src/mount.js
  3. +39 −0 tests/__snapshots__/mount-deep.test.js.snap
  4. +32 −0 tests/fixtures/memo.js
  5. +13 −0 tests/mount-deep.test.js
  6. +197 −1 yarn.lock
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "3.5.0",
"version": "3.6.0",
"name": "enzyme-to-json",
"description": "convert enzyme wrapper to a format compatible with Jest snapshot",
"main": "index.js",
@@ -48,7 +48,7 @@
},
"devDependencies": {
"@babel/cli": "^7.8.4",
"@babel/core": "^7.7.2",
"@babel/core": "^7.11.2",
"@babel/preset-env": "^7.7.1",
"@babel/preset-react": "^7.7.0",
"babel-jest": "^24.9.0",
11 changes: 9 additions & 2 deletions src/mount.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import omitBy from 'lodash/omitBy';
import isNil from 'lodash/isNil';
import {ForwardRef} from 'react-is';
import {ForwardRef, Memo} from 'react-is';

import {typeName} from 'enzyme/build/Debug';
import {childrenOfNode, propsOfNode} from 'enzyme/build/RSTTraversal';
@@ -46,12 +46,19 @@ function internalNodeToJson(node, options) {
}

if (Array.isArray(node)) {
// enzyme does some funny stuff with memo function components turning the children
// into an array resulting in undesirable snapshots
if (node.length === 1) {
return internalNodeToJson(node[0], options);
}
return node.map(child => internalNodeToJson(child, options));
}

if (
options.mode === 'deep' &&
(typeof node.type === 'function' || node.type.$$typeof === ForwardRef)
(typeof node.type === 'function' ||
node.type.$$typeof === ForwardRef ||
node.type.$$typeof === Memo)
) {
return internalNodeToJson(node.rendered, options);
}
39 changes: 39 additions & 0 deletions tests/__snapshots__/mount-deep.test.js.snap
Original file line number Diff line number Diff line change
@@ -244,6 +244,45 @@ exports[`excludes forwardRef node but renders wrapped component 1`] = `
</div>
`;

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

exports[`excludes memo node but renders wrapped top level array properly 1`] = `
Array [
<div
className="test"
key="test"
>
Test
</div>,
<div
className="test2"
key="test2"
>
Test 2
</div>,
<div
className="foo"
key="test3"
>
Test 3
</div>,
]
`;

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

exports[`includes undefined props 1`] = `
32 changes: 32 additions & 0 deletions tests/fixtures/memo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';

function BasicComponent(props) {
return (
<div
className={`basic-memo ${props.className}`}
onClick={function handleOnClick() {}}
>
<div id="group-id" className="group">
<span className="empty" />
</div>
</div>
);
}

export const BasicMemo = React.memo(BasicComponent);

function ArrayRender(props) {
return [
<div className="test" key="test">
Test
</div>,
<div className="test2" key="test2">
Test 2
</div>,
<div className={props.className} key="test3">
Test 3
</div>,
];
}

export const ArrayMemo = React.memo(ArrayRender);
13 changes: 13 additions & 0 deletions tests/mount-deep.test.js
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ import {
ClassArrayRender,
} from './fixtures/class';
import {ForwardRefWithDefaultProps} from './fixtures/forwardRef';
import {BasicMemo, ArrayMemo} from './fixtures/memo';

Enzyme.configure({adapter: new Adapter()});
const deepOptions = {mode: 'deep'};
@@ -135,3 +136,15 @@ it('excludes forwardRef node but renders wrapped component', () => {

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

it('excludes memo node but renders wrapped component', () => {
const mounted = mount(<BasicMemo className="foo" />);

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

it('excludes memo node but renders wrapped top level array properly', () => {
const mounted = mount(<ArrayMemo className="foo" />);

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