Skip to content

Commit d6ab780

Browse files
authored
Merge branch 'master' into issue1916
2 parents 9ea5242 + 79fa8ba commit d6ab780

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

.github/autorebase.workflow

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
workflow "Autorebase on merge commits" {
2+
on = "push"
3+
resolves = ["docker://ljharb/rebase:latest"]
4+
}
5+
6+
action "docker://ljharb/rebase:latest" {
7+
uses = "docker://ljharb/rebase:latest"
8+
secrets = ["GITHUB_TOKEN"]
9+
}

packages/enzyme-test-suite/test/_helpers/index.jsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,9 @@ export function generateEmptyRenderData() {
150150
{ message: 'React element', value: <noscript />, expectResponse: false },
151151
];
152152
}
153+
154+
export function delay(ms) {
155+
return new Promise((resolve) => {
156+
setTimeout(resolve, ms);
157+
});
158+
}

packages/enzyme-test-suite/test/shared/methods/props.jsx

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { expect } from 'chai';
33

44
import {
5+
delay,
56
describeIf,
67
itIf,
78
} from '../../_helpers';
@@ -122,5 +123,50 @@ export default function describeProps({
122123
});
123124
});
124125
});
126+
127+
describe('props in async handler', () => {
128+
class TestComponent extends React.Component {
129+
constructor(props) {
130+
super(props);
131+
this.state = { counter: 1 };
132+
this.handleClick = this.handleClick.bind(this);
133+
}
134+
135+
handleClick() {
136+
return delay(100).then(() => new Promise((resolve) => {
137+
this.setState({ counter: 2 }, () => {
138+
resolve();
139+
});
140+
}));
141+
}
142+
143+
render() {
144+
const { counter } = this.state;
145+
return (
146+
<div id="parentDiv" onClick={this.handleClick}>
147+
<TestSubComponent id="childDiv" counter={counter} />
148+
</div>
149+
);
150+
}
151+
}
152+
153+
class TestSubComponent extends React.Component {
154+
render() {
155+
const { counter } = this.props;
156+
return <div>{counter}</div>;
157+
}
158+
}
159+
160+
it('child component props should update after call to setState in async handler', () => {
161+
const wrapper = Wrap(<TestComponent />);
162+
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 1 });
163+
const promise = wrapper.find('#parentDiv').props().onClick();
164+
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 1 });
165+
return promise.then(() => {
166+
wrapper.update();
167+
expect(wrapper.find(TestSubComponent).props()).to.eql({ id: 'childDiv', counter: 2 });
168+
});
169+
});
170+
});
125171
});
126172
}

0 commit comments

Comments
 (0)