Skip to content

defaultProps for shallow renders do not work with React.memo #2115

@KamalAman

Description

@KamalAman

Current behavior

Default props from the "inner component" are not applied to memo'd component. The second test fails with <div>NaN</div>

import React from 'react';
import { shallow } from 'enzyme';

const Add = ({ a, b }) => <div>{a + b}</div>;

Add.defaultProps = {
  a: 2,
  b: 3,
};

const MemoAdd = React.memo(Add);

describe('Enzyme Shallow Default Props Test', () => {
  it('default props should be applied to components', () => {
    const wrapper = shallow(<Add />);
    expect(wrapper.html()).toEqual('<div>5</div>');
  });

  it('default props should be applied to memo components', () => {
    const wrapper = shallow(<MemoAdd />);
    expect(wrapper.html()).toEqual('<div>5</div>');
  });
});

Expected behavior

Default props should be applied to the memo component

Your environment

API

  • shallow
  • mount
  • render

Version

library version
enzyme 3.9.0
react 16.8.6
react-dom 16.8.6
react-test-renderer 16.8.6
adapter (below)

Adapter

  • enzyme-adapter-react-16
  • others ( )

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions