@@ -34,6 +34,8 @@ def render
34
34
end
35
35
36
36
describe 'Life Cycle' do
37
+ let ( :element_to_render ) { React . create_element ( Foo ) }
38
+
37
39
before ( :each ) do
38
40
stub_const 'Foo' , Class . new
39
41
Foo . class_eval do
@@ -54,7 +56,7 @@ def bar2; end
54
56
expect_any_instance_of ( Foo ) . to receive ( :bar )
55
57
expect_any_instance_of ( Foo ) . to receive ( :bar2 )
56
58
57
- renderToDocument ( Foo )
59
+ React :: Test :: Utils . render_into_document ( element_to_render )
58
60
end
59
61
60
62
it 'invokes `after_mount` registered methods when `componentDidMount()`' do
@@ -67,7 +69,7 @@ def bar4; end
67
69
expect_any_instance_of ( Foo ) . to receive ( :bar3 )
68
70
expect_any_instance_of ( Foo ) . to receive ( :bar4 )
69
71
70
- renderToDocument ( Foo )
72
+ React :: Test :: Utils . render_into_document ( element_to_render )
71
73
end
72
74
73
75
it 'allows multiple class declared life cycle hooker' do
@@ -88,7 +90,7 @@ def render
88
90
89
91
expect_any_instance_of ( Foo ) . to receive ( :bar )
90
92
91
- renderToDocument ( Foo )
93
+ React :: Test :: Utils . render_into_document ( element_to_render )
92
94
end
93
95
94
96
it 'allows block for life cycle callback' do
@@ -169,6 +171,8 @@ def render
169
171
end
170
172
171
173
describe 'State setter & getter' do
174
+ let ( :element_to_render ) { React . create_element ( Foo ) }
175
+
172
176
before ( :each ) do
173
177
stub_const 'Foo' , Class . new
174
178
Foo . class_eval do
@@ -188,17 +192,17 @@ def set_up
188
192
end
189
193
end
190
194
191
- element = renderToDocument ( Foo )
192
- expect ( element . state . foo ) . to be ( 'bar' )
195
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
196
+ expect ( instance . state . foo ) . to be ( 'bar' )
193
197
end
194
198
195
199
it 'defines init state by passing a block to `define_state`' do
196
200
Foo . class_eval do
197
201
define_state ( :foo ) { 10 }
198
202
end
199
203
200
- element = renderToDocument ( Foo )
201
- expect ( element . state . foo ) . to be ( 10 )
204
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
205
+ expect ( instance . state . foo ) . to be ( 10 )
202
206
end
203
207
204
208
it 'defines getter using `define_state`' do
@@ -210,8 +214,8 @@ def bump
210
214
end
211
215
end
212
216
213
- element = renderToDocument ( Foo )
214
- expect ( element . state . foo ) . to be ( 30 )
217
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
218
+ expect ( instance . state . foo ) . to be ( 30 )
215
219
end
216
220
217
221
it 'defines multiple state accessors by passing array to `define_state`' do
@@ -224,9 +228,9 @@ def set_up
224
228
end
225
229
end
226
230
227
- element = renderToDocument ( Foo )
228
- expect ( element . state . foo ) . to be ( 10 )
229
- expect ( element . state . foo2 ) . to be ( 20 )
231
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
232
+ expect ( instance . state . foo ) . to be ( 10 )
233
+ expect ( instance . state . foo2 ) . to be ( 20 )
230
234
end
231
235
232
236
it 'invokes `define_state` multiple times to define states' do
@@ -235,29 +239,30 @@ def set_up
235
239
define_state ( :foo2 ) { 40 }
236
240
end
237
241
238
- element = renderToDocument ( Foo )
239
- expect ( element . state . foo ) . to be ( 30 )
240
- expect ( element . state . foo2 ) . to be ( 40 )
242
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
243
+ expect ( instance . state . foo ) . to be ( 30 )
244
+ expect ( instance . state . foo2 ) . to be ( 40 )
241
245
end
242
246
243
247
it 'can initialize multiple state variables with a block' do
244
248
Foo . class_eval do
245
249
define_state ( :foo , :foo2 ) { 30 }
246
250
end
247
- element = renderToDocument ( Foo )
248
- expect ( element . state . foo ) . to be ( 30 )
249
- expect ( element . state . foo2 ) . to be ( 30 )
251
+
252
+ instance = React ::Test ::Utils . render_into_document ( element_to_render )
253
+ expect ( instance . state . foo ) . to be ( 30 )
254
+ expect ( instance . state . foo2 ) . to be ( 30 )
250
255
end
251
256
252
257
it 'can mix multiple state variables with initializers and a block' do
253
258
Foo . class_eval do
254
259
define_state ( :x , :y , foo : 1 , bar : 2 ) { 3 }
255
260
end
256
- element = renderToDocument ( Foo )
257
- expect ( element . state . x ) . to be ( 3 )
258
- expect ( element . state . y ) . to be ( 3 )
259
- expect ( element . state . foo ) . to be ( 1 )
260
- expect ( element . state . bar ) . to be ( 2 )
261
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
262
+ expect ( instance . state . x ) . to be ( 3 )
263
+ expect ( instance . state . y ) . to be ( 3 )
264
+ expect ( instance . state . foo ) . to be ( 1 )
265
+ expect ( instance . state . bar ) . to be ( 2 )
261
266
end
262
267
263
268
it 'gets state in render method' do
@@ -268,8 +273,8 @@ def render
268
273
end
269
274
end
270
275
271
- element = renderToDocument ( Foo )
272
- expect ( `#{ element . dom_node } .textContent` ) . to eq ( '10' )
276
+ instance = React :: Test :: Utils . render_into_document ( element_to_render )
277
+ expect ( `#{ instance . dom_node } .textContent` ) . to eq ( '10' )
273
278
end
274
279
275
280
it 'supports original `setState` as `set_state` method' do
0 commit comments