Skip to content

Commit d58071f

Browse files
committed
Remove tests from event handlers and use sync tests
1 parent da4a872 commit d58071f

File tree

1 file changed

+21
-32
lines changed

1 file changed

+21
-32
lines changed

packages/react-dom/src/__tests__/ReactDOMComponentTree-test.js

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,19 @@ describe('ReactDOMComponentTree', () => {
7878
expect(renderAndGetRef('input')).toBe('INPUT');
7979
});
8080

81-
it('finds closest instance for node when an event happens', done => {
81+
it('finds closest instance for node when an event happens', () => {
8282
const elemID = 'aID';
8383
const innerHTML = {__html: `<div id="${elemID}"></div>`};
84-
84+
const testID = 'closestInstance';
85+
let currentTargetID = null;
8586
class ClosestInstance extends React.Component {
86-
id = 'closestInstance';
8787
_onClick = e => {
88-
const node = e.currentTarget;
89-
expect(node.id).toBe(this.id);
90-
done();
88+
currentTargetID = e.currentTarget.id;
9189
};
9290
render() {
9391
return (
9492
<div
95-
id="closestInstance"
93+
id={testID}
9694
onClick={this._onClick}
9795
dangerouslySetInnerHTML={innerHTML}
9896
/>
@@ -104,41 +102,20 @@ describe('ReactDOMComponentTree', () => {
104102
const container = document.createElement('div');
105103
ReactDOM.render(<section>{component}</section>, container);
106104
document.body.appendChild(container);
105+
expect(currentTargetID).toBe(null);
107106
simulateClick(document.getElementById(elemID));
107+
expect(currentTargetID).toBe(testID);
108108
});
109109

110-
it('finds a controlled instance from node and gets its current fiber props', done => {
110+
it('finds a controlled instance from node and gets its current fiber props', () => {
111111
const inputID = 'inputID';
112112
const startValue = undefined;
113113
const finishValue = 'finish';
114114

115115
class Controlled extends React.Component {
116116
state = {value: startValue};
117117
a = null;
118-
_onChange = e => {
119-
const node = e.currentTarget;
120-
expect(node.value).toEqual(finishValue);
121-
expect(node.id).toBe(inputID);
122-
spyOn(console, 'error');
123-
expectDev(console.error.calls.count()).toBe(0);
124-
this.setState(
125-
{
126-
value: node.value,
127-
},
128-
() => {
129-
expectDev(console.error.calls.count()).toBe(1);
130-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
131-
'Warning: A component is changing an uncontrolled input of ' +
132-
'type text to be controlled. Input elements should not ' +
133-
'switch from uncontrolled to controlled (or vice versa). ' +
134-
'Decide between using a controlled or uncontrolled input ' +
135-
'element for the lifetime of the component. More info: ' +
136-
'https://fb.me/react-controlled-components',
137-
);
138-
done();
139-
},
140-
);
141-
};
118+
_onChange = e => this.setState({value: e.currentTarget.value});
142119
render() {
143120
return (
144121
<input
@@ -156,7 +133,19 @@ describe('ReactDOMComponentTree', () => {
156133
const container = document.createElement('div');
157134
const instance = ReactDOM.render(component, container);
158135
document.body.appendChild(container);
136+
spyOn(console, 'error');
137+
expectDev(console.error.calls.count()).toBe(0);
159138
simulateInput(instance.a, finishValue);
139+
expectDev(console.error.calls.count()).toBe(1);
140+
expectDev(console.error.calls.argsFor(0)[0]).toContain(
141+
'Warning: A component is changing an uncontrolled input of ' +
142+
'type text to be controlled. Input elements should not ' +
143+
'switch from uncontrolled to controlled (or vice versa). ' +
144+
'Decide between using a controlled or uncontrolled input ' +
145+
'element for the lifetime of the component. More info: ' +
146+
'https://fb.me/react-controlled-components',
147+
);
148+
160149
});
161150

162151
it('finds instance of node that is attempted to be unmounted', () => {

0 commit comments

Comments
 (0)