1313
1414var React = require ( 'React' ) ;
1515var ReactTestUtils = require ( 'ReactTestUtils' ) ;
16- var reactComponentExpect = require ( 'reactComponentExpect' ) ;
1716
1817// TODO: Test render and all stock methods.
1918describe ( 'autobind optout' , ( ) => {
@@ -36,6 +35,7 @@ describe('autobind optout', () => {
3635 render : function ( ) {
3736 return (
3837 < div
38+ ref = "child"
3939 onMouseOver = { this . onMouseEnter . bind ( this ) }
4040 onMouseOut = { this . onMouseLeave . bind ( this ) }
4141 onClick = { this . onClick . bind ( this ) }
@@ -44,41 +44,35 @@ describe('autobind optout', () => {
4444 } ,
4545 } ) ;
4646
47- var instance1 = < TestBindComponent /> ;
48- var mountedInstance1 = ReactTestUtils . renderIntoDocument ( instance1 ) ;
49- var rendered1 = reactComponentExpect ( mountedInstance1 )
50- . expectRenderedChild ( )
51- . instance ( ) ;
47+ var instance1 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
48+ var rendered1 = instance1 . refs . child ;
5249
53- var instance2 = < TestBindComponent /> ;
54- var mountedInstance2 = ReactTestUtils . renderIntoDocument ( instance2 ) ;
55- var rendered2 = reactComponentExpect ( mountedInstance2 )
56- . expectRenderedChild ( )
57- . instance ( ) ;
50+ var instance2 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
51+ var rendered2 = instance2 . refs . child ;
5852
5953 ReactTestUtils . Simulate . click ( rendered1 ) ;
6054 expect ( mouseDidClick . mock . instances . length ) . toBe ( 1 ) ;
61- expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( mountedInstance1 ) ;
55+ expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( instance1 ) ;
6256
6357 ReactTestUtils . Simulate . click ( rendered2 ) ;
6458 expect ( mouseDidClick . mock . instances . length ) . toBe ( 2 ) ;
65- expect ( mouseDidClick . mock . instances [ 1 ] ) . toBe ( mountedInstance2 ) ;
59+ expect ( mouseDidClick . mock . instances [ 1 ] ) . toBe ( instance2 ) ;
6660
6761 ReactTestUtils . Simulate . mouseOver ( rendered1 ) ;
6862 expect ( mouseDidEnter . mock . instances . length ) . toBe ( 1 ) ;
69- expect ( mouseDidEnter . mock . instances [ 0 ] ) . toBe ( mountedInstance1 ) ;
63+ expect ( mouseDidEnter . mock . instances [ 0 ] ) . toBe ( instance1 ) ;
7064
7165 ReactTestUtils . Simulate . mouseOver ( rendered2 ) ;
7266 expect ( mouseDidEnter . mock . instances . length ) . toBe ( 2 ) ;
73- expect ( mouseDidEnter . mock . instances [ 1 ] ) . toBe ( mountedInstance2 ) ;
67+ expect ( mouseDidEnter . mock . instances [ 1 ] ) . toBe ( instance2 ) ;
7468
7569 ReactTestUtils . Simulate . mouseOut ( rendered1 ) ;
7670 expect ( mouseDidLeave . mock . instances . length ) . toBe ( 1 ) ;
77- expect ( mouseDidLeave . mock . instances [ 0 ] ) . toBe ( mountedInstance1 ) ;
71+ expect ( mouseDidLeave . mock . instances [ 0 ] ) . toBe ( instance1 ) ;
7872
7973 ReactTestUtils . Simulate . mouseOut ( rendered2 ) ;
8074 expect ( mouseDidLeave . mock . instances . length ) . toBe ( 2 ) ;
81- expect ( mouseDidLeave . mock . instances [ 1 ] ) . toBe ( mountedInstance2 ) ;
75+ expect ( mouseDidLeave . mock . instances [ 1 ] ) . toBe ( instance2 ) ;
8276 } ) ;
8377
8478 it ( 'should not hold reference to instance' , ( ) => {
@@ -103,30 +97,25 @@ describe('autobind optout', () => {
10397 render : function ( ) {
10498 return (
10599 < div
100+ ref = "child"
106101 onClick = { this . onClick }
107102 />
108103 ) ;
109104 } ,
110105 } ) ;
111106
112- var instance1 = < TestBindComponent /> ;
113- var mountedInstance1 = ReactTestUtils . renderIntoDocument ( instance1 ) ;
114- var rendered1 = reactComponentExpect ( mountedInstance1 )
115- . expectRenderedChild ( )
116- . instance ( ) ;
107+ var instance1 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
108+ var rendered1 = instance1 . refs . child ;
117109
118- var instance2 = < TestBindComponent /> ;
119- var mountedInstance2 = ReactTestUtils . renderIntoDocument ( instance2 ) ;
120- var rendered2 = reactComponentExpect ( mountedInstance2 )
121- . expectRenderedChild ( )
122- . instance ( ) ;
110+ var instance2 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
111+ var rendered2 = instance2 . refs . child ;
123112
124113 expect ( function ( ) {
125114 var badIdea = instance1 . badIdeas . badBind ;
126115 badIdea ( ) ;
127116 } ) . toThrow ( ) ;
128117
129- expect ( mountedInstance1 . onClick ) . toBe ( mountedInstance2 . onClick ) ;
118+ expect ( instance1 . onClick ) . toBe ( instance2 . onClick ) ;
130119
131120 expect ( function ( ) {
132121 ReactTestUtils . Simulate . click ( rendered1 ) ;
@@ -148,19 +137,16 @@ describe('autobind optout', () => {
148137 mixins : [ TestMixin ] ,
149138
150139 render : function ( ) {
151- return < div onClick = { this . onClick } /> ;
140+ return < div ref = "child" onClick = { this . onClick } /> ;
152141 } ,
153142 } ) ;
154143
155- var instance1 = < TestBindComponent /> ;
156- var mountedInstance1 = ReactTestUtils . renderIntoDocument ( instance1 ) ;
157- var rendered1 = reactComponentExpect ( mountedInstance1 )
158- . expectRenderedChild ( )
159- . instance ( ) ;
144+ var instance1 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
145+ var rendered1 = instance1 . refs . child ;
160146
161147 ReactTestUtils . Simulate . click ( rendered1 ) ;
162148 expect ( mouseDidClick . mock . instances . length ) . toBe ( 1 ) ;
163- expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( mountedInstance1 ) ;
149+ expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( instance1 ) ;
164150 } ) ;
165151
166152 it ( 'works with mixins that have opted out of autobinding' , ( ) => {
@@ -175,19 +161,16 @@ describe('autobind optout', () => {
175161 mixins : [ TestMixin ] ,
176162
177163 render : function ( ) {
178- return < div onClick = { this . onClick . bind ( this ) } /> ;
164+ return < div ref = "child" onClick = { this . onClick . bind ( this ) } /> ;
179165 } ,
180166 } ) ;
181167
182- var instance1 = < TestBindComponent /> ;
183- var mountedInstance1 = ReactTestUtils . renderIntoDocument ( instance1 ) ;
184- var rendered1 = reactComponentExpect ( mountedInstance1 )
185- . expectRenderedChild ( )
186- . instance ( ) ;
168+ var instance1 = ReactTestUtils . renderIntoDocument ( < TestBindComponent /> ) ;
169+ var rendered1 = instance1 . refs . child ;
187170
188171 ReactTestUtils . Simulate . click ( rendered1 ) ;
189172 expect ( mouseDidClick . mock . instances . length ) . toBe ( 1 ) ;
190- expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( mountedInstance1 ) ;
173+ expect ( mouseDidClick . mock . instances [ 0 ] ) . toBe ( instance1 ) ;
191174 } ) ;
192175
193176 it ( 'does not warn if you try to bind to this' , ( ) => {
0 commit comments