Skip to content

Commit

Permalink
Merge branch 'master' into issue1916
Browse files Browse the repository at this point in the history
  • Loading branch information
sstern6 committed Apr 10, 2019
2 parents 9ea5242 + 79fa8ba commit d6ab780
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .github/autorebase.workflow
@@ -0,0 +1,9 @@
workflow "Autorebase on merge commits" {
on = "push"
resolves = ["docker://ljharb/rebase:latest"]
}

action "docker://ljharb/rebase:latest" {
uses = "docker://ljharb/rebase:latest"
secrets = ["GITHUB_TOKEN"]
}
6 changes: 6 additions & 0 deletions packages/enzyme-test-suite/test/_helpers/index.jsx
Expand Up @@ -150,3 +150,9 @@ export function generateEmptyRenderData() {
{ message: 'React element', value: <noscript />, expectResponse: false },
];
}

export function delay(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
46 changes: 46 additions & 0 deletions packages/enzyme-test-suite/test/shared/methods/props.jsx
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { expect } from 'chai';

import {
delay,
describeIf,
itIf,
} from '../../_helpers';
Expand Down Expand Up @@ -122,5 +123,50 @@ export default function describeProps({
});
});
});

describe('props in async handler', () => {
class TestComponent extends React.Component {
constructor(props) {
super(props);
this.state = { counter: 1 };
this.handleClick = this.handleClick.bind(this);
}

handleClick() {
return delay(100).then(() => new Promise((resolve) => {
this.setState({ counter: 2 }, () => {
resolve();
});
}));
}

render() {
const { counter } = this.state;
return (
<div id="parentDiv" onClick={this.handleClick}>
<TestSubComponent id="childDiv" counter={counter} />
</div>
);
}
}

class TestSubComponent extends React.Component {
render() {
const { counter } = this.props;
return <div>{counter}</div>;
}
}

it('child component props should update after call to setState in async handler', () => {
const wrapper = Wrap(<TestComponent />);
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 1 });
const promise = wrapper.find('#parentDiv').props().onClick();
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 1 });
return promise.then(() => {
wrapper.update();
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 2 });
});
});
});
});
}

0 comments on commit d6ab780

Please sign in to comment.