Skip to content

Commit ba950fc

Browse files
committed
Revert codemod where tests explicitly test string refs
1 parent bebc868 commit ba950fc

14 files changed

+44
-284
lines changed

fixtures/legacy-jsx-runtimes/react-14/react-14.test.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ it('does not reuse the object that is spread into props', () => {
9393
});
9494

9595
it('extracts key and ref from the rest of the props', () => {
96-
const element = (
97-
<Component
98-
key="12"
99-
ref={current => {
100-
this.refs['34'] = current;
101-
}}
102-
foo="56"
103-
/>
104-
);
96+
const element = <Component key="12" ref="34" foo="56" />;
10597
expect(element.type).toBe(Component);
10698
expect(element.key).toBe('12');
10799
expect(element.ref).toBe('34');
@@ -543,14 +535,7 @@ xit('does not call lazy initializers eagerly', () => {
543535
it('supports classic refs', () => {
544536
class Foo extends React.Component {
545537
render() {
546-
return (
547-
<div
548-
className="foo"
549-
ref={current => {
550-
this.refs['inner'] = current;
551-
}}
552-
/>
553-
);
538+
return <div className="foo" ref="inner" />;
554539
}
555540
}
556541
const container = document.createElement('div');
@@ -574,20 +559,9 @@ it('should support refs on owned components', () => {
574559

575560
class Component extends React.Component {
576561
render() {
577-
const inner = (
578-
<Wrapper
579-
object={innerObj}
580-
ref={current => {
581-
this.refs['inner'] = current;
582-
}}
583-
/>
584-
);
562+
const inner = <Wrapper object={innerObj} ref="inner" />;
585563
const outer = (
586-
<Wrapper
587-
object={outerObj}
588-
ref={current => {
589-
this.refs['outer'] = current;
590-
}}>
564+
<Wrapper object={outerObj} ref="outer">
591565
{inner}
592566
</Wrapper>
593567
);
@@ -769,11 +743,7 @@ it('should warn when `ref` is being accessed', () => {
769743
render() {
770744
return (
771745
<div>
772-
<Child
773-
ref={current => {
774-
this.refs['childElement'] = current;
775-
}}
776-
/>
746+
<Child ref="childElement" />
777747
</div>
778748
);
779749
}
@@ -800,15 +770,7 @@ it('should NOT warn when owner and self are different for string refs', () => {
800770
class ClassParent extends React.Component {
801771
render() {
802772
return (
803-
<ClassWithRenderProp>
804-
{() => (
805-
<div
806-
ref={current => {
807-
this.refs['myRef'] = current;
808-
}}
809-
/>
810-
)}
811-
</ClassWithRenderProp>
773+
<ClassWithRenderProp>{() => <div ref="myRef" />}</ClassWithRenderProp>
812774
);
813775
}
814776
}

fixtures/legacy-jsx-runtimes/react-15/react-15.test.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ it('does not reuse the object that is spread into props', () => {
9393
});
9494

9595
it('extracts key and ref from the rest of the props', () => {
96-
const element = (
97-
<Component
98-
key="12"
99-
ref={current => {
100-
this.refs['34'] = current;
101-
}}
102-
foo="56"
103-
/>
104-
);
96+
const element = <Component key="12" ref="34" foo="56" />;
10597
expect(element.type).toBe(Component);
10698
expect(element.key).toBe('12');
10799
expect(element.ref).toBe('34');
@@ -538,14 +530,7 @@ xit('does not call lazy initializers eagerly', () => {
538530
it('supports classic refs', () => {
539531
class Foo extends React.Component {
540532
render() {
541-
return (
542-
<div
543-
className="foo"
544-
ref={current => {
545-
this.refs['inner'] = current;
546-
}}
547-
/>
548-
);
533+
return <div className="foo" ref="inner" />;
549534
}
550535
}
551536
const container = document.createElement('div');
@@ -569,20 +554,9 @@ it('should support refs on owned components', () => {
569554

570555
class Component extends React.Component {
571556
render() {
572-
const inner = (
573-
<Wrapper
574-
object={innerObj}
575-
ref={current => {
576-
this.refs['inner'] = current;
577-
}}
578-
/>
579-
);
557+
const inner = <Wrapper object={innerObj} ref="inner" />;
580558
const outer = (
581-
<Wrapper
582-
object={outerObj}
583-
ref={current => {
584-
this.refs['outer'] = current;
585-
}}>
559+
<Wrapper object={outerObj} ref="outer">
586560
{inner}
587561
</Wrapper>
588562
);
@@ -764,11 +738,7 @@ it('should warn when `ref` is being accessed', () => {
764738
render() {
765739
return (
766740
<div>
767-
<Child
768-
ref={current => {
769-
this.refs['childElement'] = current;
770-
}}
771-
/>
741+
<Child ref="childElement" />
772742
</div>
773743
);
774744
}
@@ -795,15 +765,7 @@ it('should NOT warn when owner and self are different for string refs', () => {
795765
class ClassParent extends React.Component {
796766
render() {
797767
return (
798-
<ClassWithRenderProp>
799-
{() => (
800-
<div
801-
ref={current => {
802-
this.refs['myRef'] = current;
803-
}}
804-
/>
805-
)}
806-
</ClassWithRenderProp>
768+
<ClassWithRenderProp>{() => <div ref="myRef" />}</ClassWithRenderProp>
807769
);
808770
}
809771
}

fixtures/legacy-jsx-runtimes/react-16/react-16.test.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ it('does not reuse the object that is spread into props', () => {
9393
});
9494

9595
it('extracts key and ref from the rest of the props', () => {
96-
const element = (
97-
<Component
98-
key="12"
99-
ref={current => {
100-
this.refs['34'] = current;
101-
}}
102-
foo="56"
103-
/>
104-
);
96+
const element = <Component key="12" ref="34" foo="56" />;
10597
expect(element.type).toBe(Component);
10698
expect(element.key).toBe('12');
10799
expect(element.ref).toBe('34');
@@ -533,14 +525,7 @@ it('does not call lazy initializers eagerly', () => {
533525
it('supports classic refs', () => {
534526
class Foo extends React.Component {
535527
render() {
536-
return (
537-
<div
538-
className="foo"
539-
ref={current => {
540-
this.refs['inner'] = current;
541-
}}
542-
/>
543-
);
528+
return <div className="foo" ref="inner" />;
544529
}
545530
}
546531
const container = document.createElement('div');
@@ -564,20 +549,9 @@ it('should support refs on owned components', () => {
564549

565550
class Component extends React.Component {
566551
render() {
567-
const inner = (
568-
<Wrapper
569-
object={innerObj}
570-
ref={current => {
571-
this.refs['inner'] = current;
572-
}}
573-
/>
574-
);
552+
const inner = <Wrapper object={innerObj} ref="inner" />;
575553
const outer = (
576-
<Wrapper
577-
object={outerObj}
578-
ref={current => {
579-
this.refs['outer'] = current;
580-
}}>
554+
<Wrapper object={outerObj} ref="outer">
581555
{inner}
582556
</Wrapper>
583557
);
@@ -755,11 +729,7 @@ it('should warn when `ref` is being accessed', () => {
755729
render() {
756730
return (
757731
<div>
758-
<Child
759-
ref={current => {
760-
this.refs['childElement'] = current;
761-
}}
762-
/>
732+
<Child ref="childElement" />
763733
</div>
764734
);
765735
}
@@ -782,15 +752,7 @@ it('should warn when owner and self are different for string refs', () => {
782752
class ClassParent extends React.Component {
783753
render() {
784754
return (
785-
<ClassWithRenderProp>
786-
{() => (
787-
<div
788-
ref={current => {
789-
this.refs['myRef'] = current;
790-
}}
791-
/>
792-
)}
793-
</ClassWithRenderProp>
755+
<ClassWithRenderProp>{() => <div ref="myRef" />}</ClassWithRenderProp>
794756
);
795757
}
796758
}

fixtures/legacy-jsx-runtimes/react-17/react-17.test.js

Lines changed: 6 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,7 @@ it('does not reuse the object that is spread into props', () => {
9393
});
9494

9595
it('extracts key and ref from the rest of the props', () => {
96-
const element = (
97-
<Component
98-
key="12"
99-
ref={current => {
100-
this.refs['34'] = current;
101-
}}
102-
foo="56"
103-
/>
104-
);
96+
const element = <Component key="12" ref="34" foo="56" />;
10597
expect(element.type).toBe(Component);
10698
expect(element.key).toBe('12');
10799
expect(element.ref).toBe('34');
@@ -533,14 +525,7 @@ it('does not call lazy initializers eagerly', () => {
533525
it('supports classic refs', () => {
534526
class Foo extends React.Component {
535527
render() {
536-
return (
537-
<div
538-
className="foo"
539-
ref={current => {
540-
this.refs['inner'] = current;
541-
}}
542-
/>
543-
);
528+
return <div className="foo" ref="inner" />;
544529
}
545530
}
546531
const container = document.createElement('div');
@@ -564,20 +549,9 @@ it('should support refs on owned components', () => {
564549

565550
class Component extends React.Component {
566551
render() {
567-
const inner = (
568-
<Wrapper
569-
object={innerObj}
570-
ref={current => {
571-
this.refs['inner'] = current;
572-
}}
573-
/>
574-
);
552+
const inner = <Wrapper object={innerObj} ref="inner" />;
575553
const outer = (
576-
<Wrapper
577-
object={outerObj}
578-
ref={current => {
579-
this.refs['outer'] = current;
580-
}}>
554+
<Wrapper object={outerObj} ref="outer">
581555
{inner}
582556
</Wrapper>
583557
);
@@ -755,11 +729,7 @@ it('should warn when `ref` is being accessed', () => {
755729
render() {
756730
return (
757731
<div>
758-
<Child
759-
ref={current => {
760-
this.refs['childElement'] = current;
761-
}}
762-
/>
732+
<Child ref="childElement" />
763733
</div>
764734
);
765735
}
@@ -782,15 +752,7 @@ it('should warn when owner and self are different for string refs', () => {
782752
class ClassParent extends React.Component {
783753
render() {
784754
return (
785-
<ClassWithRenderProp>
786-
{() => (
787-
<div
788-
ref={current => {
789-
this.refs['myRef'] = current;
790-
}}
791-
/>
792-
)}
793-
</ClassWithRenderProp>
755+
<ClassWithRenderProp>{() => <div ref="myRef" />}</ClassWithRenderProp>
794756
);
795757
}
796758
}

0 commit comments

Comments
 (0)