Skip to content

Commit 3927101

Browse files
committed
Adjust tests that were missed by codemod
1 parent 5c3f482 commit 3927101

File tree

3 files changed

+62
-32
lines changed

3 files changed

+62
-32
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ class FriendsStatusDisplay extends React.Component {
116116
!status ? null : (
117117
<StatusDisplay
118118
key={key}
119-
ref={key}
119+
ref={current => {
120+
this.refs[key] = current;
121+
}}
120122
contentKey={key}
121123
onFlush={this.verifyPreviousRefsResolved.bind(this, key)}
122124
status={status}

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

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class ClickCounter extends React.Component {
3636
<div
3737
className="clickLogDiv"
3838
key={'clickLog' + i}
39-
ref={'clickLog' + i}
39+
ref={current => {
40+
this.refs['clickLog' + i] = current;
41+
}}
4042
/>,
4143
);
4244
}
@@ -73,7 +75,11 @@ class TestRefsComponent extends React.Component {
7375
<div>
7476
<div
7577
ref={current => {
76-
this.refs.resetDiv = current;
78+
if (current === null) {
79+
delete this.refs.resetDiv;
80+
} else {
81+
this.refs.resetDiv = current;
82+
}
7783
}}
7884
onClick={this.doReset}>
7985
Reset Me By Clicking This.
@@ -94,15 +100,6 @@ class TestRefsComponent extends React.Component {
94100
}
95101
}
96102

97-
const expectClickLogsLengthToBe = function(instance, length) {
98-
const clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
99-
instance,
100-
'clickLogDiv',
101-
);
102-
expect(clickLogs.length).toBe(length);
103-
expect(Object.keys(instance.refs.myCounter.refs).length).toBe(length);
104-
};
105-
106103
describe('reactiverefs', () => {
107104
let container;
108105

@@ -149,22 +146,47 @@ describe('reactiverefs', () => {
149146
'clickIncrementer',
150147
);
151148

152-
expectClickLogsLengthToBe(testRefsComponent, 1);
149+
let clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
150+
testRefsComponent,
151+
'clickLogDiv',
152+
);
153+
expect(clickLogs.length).toBe(1);
154+
expect(Object.keys(testRefsComponent.refs.myCounter.refs)).toHaveLength(1);
153155

154156
// After clicking the reset, there should still only be one click log ref.
155157
testRefsComponent.refs.resetDiv.click();
156-
expectClickLogsLengthToBe(testRefsComponent, 1);
158+
clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
159+
testRefsComponent,
160+
'clickLogDiv',
161+
);
162+
expect(clickLogs.length).toBe(1);
163+
expect(Object.keys(testRefsComponent.refs.myCounter.refs)).toHaveLength(1);
157164

158165
// Begin incrementing clicks (and therefore refs).
159166
clickIncrementer.click();
160-
expectClickLogsLengthToBe(testRefsComponent, 2);
167+
clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
168+
testRefsComponent,
169+
'clickLogDiv',
170+
);
171+
expect(clickLogs.length).toBe(2);
172+
expect(Object.keys(testRefsComponent.refs.myCounter.refs)).toHaveLength(2);
161173

162174
clickIncrementer.click();
163-
expectClickLogsLengthToBe(testRefsComponent, 3);
175+
clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
176+
testRefsComponent,
177+
'clickLogDiv',
178+
);
179+
expect(clickLogs.length).toBe(3);
180+
expect(Object.keys(testRefsComponent.refs.myCounter.refs)).toHaveLength(3);
164181

165182
// Now reset again
166183
testRefsComponent.refs.resetDiv.click();
167-
expectClickLogsLengthToBe(testRefsComponent, 1);
184+
clickLogs = ReactTestUtils.scryRenderedDOMComponentsWithClass(
185+
testRefsComponent,
186+
'clickLogDiv',
187+
);
188+
expect(clickLogs.length).toBe(1);
189+
expect(Object.keys(testRefsComponent.refs.myCounter.refs)).toHaveLength(3);
168190
});
169191
});
170192

@@ -230,15 +252,21 @@ describe('ref swapping', () => {
230252
<div>
231253
<div
232254
className="first"
233-
ref={count % 3 === 0 ? 'hopRef' : 'divOneRef'}
255+
ref={current => {
256+
this.refs[count % 3 === 0 ? 'hopRef' : 'divOneRef'] = current;
257+
}}
234258
/>
235259
<div
236260
className="second"
237-
ref={count % 3 === 1 ? 'hopRef' : 'divTwoRef'}
261+
ref={current => {
262+
this.refs[count % 3 === 1 ? 'hopRef' : 'divTwoRef'] = current;
263+
}}
238264
/>
239265
<div
240266
className="third"
241-
ref={count % 3 === 2 ? 'hopRef' : 'divThreeRef'}
267+
ref={current => {
268+
this.refs[count % 3 === 2 ? 'hopRef' : 'divThreeRef'] = current;
269+
}}
242270
/>
243271
</div>
244272
);
@@ -482,18 +510,11 @@ describe('root level refs', () => {
482510
});
483511
});
484512

485-
describe('creating element with ref in constructor', () => {
513+
describe('creating element with string ref in constructor', () => {
486514
class RefTest extends React.Component {
487515
constructor(props) {
488516
super(props);
489-
this.p = (
490-
<p
491-
ref={current => {
492-
this.refs.p = current;
493-
}}>
494-
Hello!
495-
</p>
496-
);
517+
this.p = <p ref="p">Hello!</p>;
497518
}
498519

499520
render() {

packages/react/src/__tests__/ReactElementClone-test.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,12 +185,15 @@ describe('ReactElementClone', () => {
185185
it('should support keys and refs', () => {
186186
class Parent extends React.Component {
187187
render() {
188+
const ref = current => {
189+
this.refs.xyz = current;
190+
};
188191
const clone = React.cloneElement(this.props.children, {
189192
key: 'xyz',
190-
ref: 'xyz',
193+
ref: ref,
191194
});
192195
expect(clone.key).toBe('xyz');
193-
expect(clone.ref).toBe('xyz');
196+
expect(clone.ref).toBe(ref);
194197
return <div>{clone}</div>;
195198
}
196199
}
@@ -215,7 +218,11 @@ describe('ReactElementClone', () => {
215218
it('should steal the ref if a new ref is specified', () => {
216219
class Parent extends React.Component {
217220
render() {
218-
const clone = React.cloneElement(this.props.children, {ref: 'xyz'});
221+
const clone = React.cloneElement(this.props.children, {
222+
ref: current => {
223+
this.refs.xyz = current;
224+
},
225+
});
219226
return <div>{clone}</div>;
220227
}
221228
}

0 commit comments

Comments
 (0)