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: enzymejs/enzyme
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: enzyme@3.4.0
Choose a base ref
...
head repository: enzymejs/enzyme
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: enzyme@3.4.1
Choose a head ref
  • 4 commits
  • 6 files changed
  • 2 contributors

Commits on Aug 8, 2018

  1. Copy the full SHA
    ef8fbd9 View commit details
  2. Merge pull request #1734 from koba04/patch-1

    Fix an adapter table style in README.md
    ljharb authored Aug 8, 2018

    Verified

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

    This commit was signed with the committer’s verified signature.
    ljharb Jordan Harband
    Copy the full SHA
    9b4d027 View commit details
  4. [enzyme] v3.4.1

    ljharb committed Aug 8, 2018

    Verified

    This commit was signed with the committer’s verified signature.
    ljharb Jordan Harband
    Copy the full SHA
    eb0841d View commit details
Showing with 154 additions and 6 deletions.
  1. +11 −1 CHANGELOG.md
  2. +1 −1 README.md
  3. +1 −1 docs/guides/migration-from-2-to-3.md
  4. +139 −1 packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
  5. +1 −1 packages/enzyme/package.json
  6. +1 −1 packages/enzyme/src/ShallowWrapper.js
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 3.4.1

### Fixes

- @ljharb: `shallow`: `setProps`: merge instead of replace props ([commit](https://github.com/airbnb/enzyme/commit/9b4d0276f57e54be06aca6c3636120b3c4053310))

### Documentation

- @koba04: Fix an adapter table style in README.md and a migration guide ([#1734](https://github.com/airbnb/enzyme/pull/1734))

## 3.4.0

### New Stuff
@@ -46,7 +56,7 @@
- @ljharb: `Utils`: `configuration`: change to named exports. ([commit](https://github.com/airbnb/enzyme/commit/d7f32617e6ea93b739f4e4c3f6228a8e382aeb06))
- @ljharb: use `array.prototype.flat` ([commit](https://github.com/airbnb/enzyme/commit/e52a02ddac0fab0d1d93fd57d7f073f8bdc850bf))

### Docs
### Documentation

- @jack-lewin: Clarify dev workflow in CONTRIBUTING.md ([#1207](https://github.com/airbnb/enzyme/pull/1207))
- @robrichard: Provide migration instructions for `ref(refName)` ([#1470](https://github.com/airbnb/enzyme/pull/1470))
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -43,7 +43,7 @@ React:
| `enzyme-adapter-react-16` | `^16.4.0-0` |
| `enzyme-adapter-react-16.3` | `~16.3.0-0` |
| `enzyme-adapter-react-16.2` | `~16.2` |
| `enzyme-adapter-react-16.1` | `~16.0.0-0 || ~16.1` |
| `enzyme-adapter-react-16.1` | `~16.0.0-0 \|\| ~16.1` |
| `enzyme-adapter-react-15` | `^15.5.0` |
| `enzyme-adapter-react-15.4` | `15.0.0-0 - 15.4.x` |
| `enzyme-adapter-react-14` | `^0.14.0` |
2 changes: 1 addition & 1 deletion docs/guides/migration-from-2-to-3.md
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ The list of adapter npm packages for React semver ranges are as follows:
| `enzyme-adapter-react-16` | `^16.4.0-0` |
| `enzyme-adapter-react-16.3` | `~16.3.0-0` |
| `enzyme-adapter-react-16.2` | `~16.2` |
| `enzyme-adapter-react-16.1` | `~16.0.0-0 || ~16.1` |
| `enzyme-adapter-react-16.1` | `~16.0.0-0 \|\| ~16.1` |
| `enzyme-adapter-react-15` | `^15.5.0` |
| `enzyme-adapter-react-15.4` | `15.0.0-0 - 15.4.x` |
| `enzyme-adapter-react-14` | `^0.14.0` |
140 changes: 139 additions & 1 deletion packages/enzyme-test-suite/test/ShallowWrapper-spec.jsx
Original file line number Diff line number Diff line change
@@ -1319,7 +1319,7 @@ describe('shallow', () => {
render() {
return (
<div className={this.props.id}>
{this.props.id}
{this.props.foo}
</div>
);
}
@@ -1330,6 +1330,144 @@ describe('shallow', () => {
expect(wrapper.find('.bar')).to.have.lengthOf(1);
});

describe.only('merging props', () => {
it('merges, not replaces, props when rerendering', () => {
class Foo extends React.Component {
render() {
return (
<div className={this.props.id}>
{this.props.foo}
</div>
);
}
}

const wrapper = shallow(<Foo id="foo" foo="bar" />);

expect(wrapper.debug()).to.equal(`
<div className="foo">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'foo',
children: 'bar',
});
expect(wrapper.instance().props).to.eql({
id: 'foo',
foo: 'bar',
});

wrapper.setProps({ id: 'bar' });

expect(wrapper.debug()).to.equal(`
<div className="bar">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'bar',
children: 'bar',
});
expect(wrapper.instance().props).to.eql({
id: 'bar',
foo: 'bar',
});
});

itIf(is('> 0.13'), 'merges, not replaces, props on SFCs', () => {
function Foo({ id, foo }) {
return (
<div className={id}>
{foo}
</div>
);
}
const wrapper = shallow(<Foo id="foo" foo="bar" />);

expect(wrapper.debug()).to.equal(`
<div className="foo">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'foo',
children: 'bar',
});
if (is('< 16')) {
expect(wrapper.instance().props).to.eql({
id: 'foo',
foo: 'bar',
});
}

wrapper.setProps({ id: 'bar' });

expect(wrapper.debug()).to.equal(`
<div className="bar">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'bar',
children: 'bar',
});
if (is('< 16')) {
expect(wrapper.instance().props).to.eql({
id: 'bar',
foo: 'bar',
});
}
});

it('merges, not replaces, props when no rerender is needed', () => {
class Foo extends React.Component {
shouldComponentUpdate() {
return false;
}

render() {
return (
<div className={this.props.id}>
{this.props.foo}
</div>
);
}
}
const wrapper = shallow(<Foo id="foo" foo="bar" />);

expect(wrapper.debug()).to.equal(`
<div className="foo">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'foo',
children: 'bar',
});
expect(wrapper.instance().props).to.eql({
id: 'foo',
foo: 'bar',
});

wrapper.setProps({ id: 'foo' });

expect(wrapper.debug()).to.equal(`
<div className="foo">
bar
</div>
`.trim());
expect(wrapper.props()).to.eql({
className: 'foo',
children: 'bar',
});
expect(wrapper.instance().props).to.eql({
id: 'foo',
foo: 'bar',
});
});
});

it('should call componentWillReceiveProps for new renders', () => {
const stateValue = {};

2 changes: 1 addition & 1 deletion packages/enzyme/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "enzyme",
"version": "3.4.0",
"version": "3.4.1",
"description": "JavaScript Testing utilities for React",
"homepage": "http://airbnb.io/enzyme/",
"main": "build",
2 changes: 1 addition & 1 deletion packages/enzyme/src/ShallowWrapper.js
Original file line number Diff line number Diff line change
@@ -358,7 +358,7 @@ class ShallowWrapper {
}
// If it doesn't need to rerender, update only its props.
} else if (props) {
instance.props = props;
instance.props = (Object.freeze || Object)({ ...instance.props, ...props });
}
this.update();
});