1
1
require "spec_helper"
2
2
3
3
describe React ::Component do
4
- after ( :each ) do
5
- React ::ComponentFactory . clear_component_class_cache
6
- end
7
-
8
4
it "should define component spec methods" do
9
5
stub_const 'Foo' , Class . new
10
6
Foo . class_eval do
@@ -50,7 +46,7 @@ def bar2; end
50
46
expect_any_instance_of ( Foo ) . to receive ( :bar )
51
47
expect_any_instance_of ( Foo ) . to receive ( :bar2 )
52
48
53
- renderToDocument ( Foo )
49
+ render_to_document ( React . create_element ( Foo ) )
54
50
end
55
51
56
52
it "should invoke `after_mount` registered methods when `componentDidMount()`" do
@@ -63,7 +59,7 @@ def bar4; end
63
59
expect_any_instance_of ( Foo ) . to receive ( :bar3 )
64
60
expect_any_instance_of ( Foo ) . to receive ( :bar4 )
65
61
66
- renderToDocument ( Foo )
62
+ render_to_document ( React . create_element ( Foo ) )
67
63
end
68
64
69
65
it "should allow multiple class declared life cycle hooker" do
@@ -84,7 +80,7 @@ def render
84
80
85
81
expect_any_instance_of ( Foo ) . to receive ( :bar )
86
82
87
- renderToDocument ( Foo )
83
+ render_to_document ( React . create_element ( Foo ) )
88
84
end
89
85
90
86
it "should allow block for life cycle callback" do
@@ -96,8 +92,8 @@ def render
96
92
end
97
93
end
98
94
99
- element = renderToDocument ( Foo )
100
- expect ( element . state [ :foo ] ) . to be ( "bar" )
95
+ instance = render_to_document ( React . create_element ( Foo ) )
96
+ expect ( instance . state [ :foo ] ) . to be ( "bar" )
101
97
end
102
98
end
103
99
@@ -121,17 +117,17 @@ def set_up
121
117
end
122
118
end
123
119
124
- element = renderToDocument ( Foo )
125
- expect ( element . state [ :foo ] ) . to be ( "bar" )
120
+ instance = render_to_document ( React . create_element ( Foo ) )
121
+ expect ( instance . state [ :foo ] ) . to be ( "bar" )
126
122
end
127
123
128
124
it "should define init state by passing a block to `define_state`" do
129
125
Foo . class_eval do
130
126
define_state ( :foo ) { 10 }
131
127
end
132
128
133
- element = renderToDocument ( Foo )
134
- expect ( element . state [ :foo ] ) . to be ( 10 )
129
+ instance = render_to_document ( React . create_element ( Foo ) )
130
+ expect ( instance . state [ :foo ] ) . to be ( 10 )
135
131
end
136
132
137
133
it "should define getter using `define_state`" do
@@ -143,8 +139,8 @@ def bump
143
139
end
144
140
end
145
141
146
- element = renderToDocument ( Foo )
147
- expect ( element . state [ :foo ] ) . to be ( 30 )
142
+ instance = render_to_document ( React . create_element ( Foo ) )
143
+ expect ( instance . state [ :foo ] ) . to be ( 30 )
148
144
end
149
145
150
146
it "should define multiple state accessor by passing symols array to `define_state`" do
@@ -157,9 +153,9 @@ def set_up
157
153
end
158
154
end
159
155
160
- element = renderToDocument ( Foo )
161
- expect ( element . state [ :foo ] ) . to be ( 10 )
162
- expect ( element . state [ :foo2 ] ) . to be ( 20 )
156
+ instance = render_to_document ( React . create_element ( Foo ) )
157
+ expect ( instance . state [ :foo ] ) . to be ( 10 )
158
+ expect ( instance . state [ :foo2 ] ) . to be ( 20 )
163
159
end
164
160
165
161
it "should invoke `define_state` multiple times to define states" do
@@ -168,9 +164,9 @@ def set_up
168
164
define_state ( :foo2 ) { 40 }
169
165
end
170
166
171
- element = renderToDocument ( Foo )
172
- expect ( element . state [ :foo ] ) . to be ( 30 )
173
- expect ( element . state [ :foo2 ] ) . to be ( 40 )
167
+ instance = render_to_document ( React . create_element ( Foo ) )
168
+ expect ( instance . state [ :foo ] ) . to be ( 30 )
169
+ expect ( instance . state [ :foo2 ] ) . to be ( 40 )
174
170
end
175
171
176
172
it "should raise error if multiple states and block given at the same time" do
@@ -189,8 +185,8 @@ def render
189
185
end
190
186
end
191
187
192
- element = renderToDocument ( Foo )
193
- expect ( element . dom_node . textContent ) . to eq ( "10" )
188
+ instance = render_to_document ( React . create_element ( Foo ) )
189
+ expect ( instance . dom_node . textContent ) . to eq ( "10" )
194
190
end
195
191
196
192
it "should support original `setState` as `set_state` method" do
@@ -200,8 +196,8 @@ def render
200
196
end
201
197
end
202
198
203
- element = renderToDocument ( Foo )
204
- expect ( element . state [ :foo ] ) . to be ( "bar" )
199
+ instance = render_to_document ( React . create_element ( Foo ) )
200
+ expect ( instance . state [ :foo ] ) . to be ( "bar" )
205
201
end
206
202
207
203
it "should support originl `state` method" do
@@ -251,8 +247,8 @@ def render
251
247
end
252
248
end
253
249
254
- element = renderToDocument ( Foo , prop : "foobar" )
255
- expect ( element . dom_node . textContent ) . to eq ( "foobar" )
250
+ instance = render_to_document ( React . create_element ( Foo , prop : "foobar" ) )
251
+ expect ( instance . dom_node . textContent ) . to eq ( "foobar" )
256
252
end
257
253
258
254
it "should access nested params as orignal Ruby object" do
@@ -262,8 +258,8 @@ def render
262
258
end
263
259
end
264
260
265
- element = renderToDocument ( Foo , prop : [ { foo : 10 } ] )
266
- expect ( element . dom_node . textContent ) . to eq ( "10" )
261
+ instance = render_to_document ( React . create_element ( Foo , prop : [ { foo : 10 } ] ) )
262
+ expect ( instance . dom_node . textContent ) . to eq ( "10" )
267
263
end
268
264
end
269
265
@@ -303,7 +299,7 @@ def render; div; end
303
299
var org_console = window.console;
304
300
window.console = {warn: function(str){log.push(str)}}
305
301
}
306
- renderToDocument ( Foo , bar : 10 , lorem : Lorem . new )
302
+ render_to_document ( React . create_element ( Foo , bar : 10 , lorem : Lorem . new ) )
307
303
`window.console = org_console;`
308
304
expect ( `log` ) . to eq ( [ "Warning: Failed propType: In component `Foo`\n Required prop `foo` was not specified\n Provided prop `bar` was not the specified type `String`" ] )
309
305
end
@@ -325,7 +321,7 @@ def render; div; end
325
321
var org_console = window.console;
326
322
window.console = {warn: function(str){log.push(str)}}
327
323
}
328
- renderToDocument ( Foo , foo : 10 , bar : "10" , lorem : Lorem . new )
324
+ render_to_document ( React . create_element ( Foo , foo : 10 , bar : "10" , lorem : Lorem . new ) )
329
325
`window.console = org_console;`
330
326
expect ( `log` ) . to eq ( [ ] )
331
327
end
@@ -371,9 +367,8 @@ def render
371
367
end
372
368
end
373
369
374
- element = React . create_element ( Foo )
375
- instance = renderElementToDocument ( element )
376
- simulateEvent ( :click , instance )
370
+ instance = render_to_document ( React . create_element ( Foo ) )
371
+ simulate_event ( :click , React . find_dom_node ( instance ) )
377
372
expect ( instance . state [ :clicked ] ) . to eq ( true )
378
373
end
379
374
@@ -392,7 +387,7 @@ def render
392
387
393
388
expect { |b |
394
389
element = React . create_element ( Foo ) . on ( :foo_submit , &b )
395
- renderElementToDocument ( element )
390
+ render_to_document ( element )
396
391
} . to yield_with_args ( "bar" )
397
392
end
398
393
@@ -411,7 +406,7 @@ def render
411
406
412
407
expect { |b |
413
408
element = React . create_element ( Foo ) . on ( :foo_invoked , &b )
414
- renderElementToDocument ( element )
409
+ render_to_document ( element )
415
410
} . to yield_with_args ( [ 1 , 2 , 3 ] , "bar" )
416
411
end
417
412
end
@@ -431,8 +426,8 @@ def render
431
426
end
432
427
end
433
428
434
- element = renderToDocument ( Foo )
435
- expect ( element . refs [ :field ] ) . not_to be_nil
429
+ instance = render_to_document ( React . create_element ( Foo ) )
430
+ expect ( instance . refs [ :field ] ) . not_to be_nil
436
431
end
437
432
438
433
it "should access refs through `refs` method" do
@@ -444,10 +439,10 @@ def render
444
439
end
445
440
end
446
441
447
- element = renderToDocument ( Foo )
448
- simulateEvent ( :click , element )
442
+ instance = render_to_document ( React . create_element ( Foo ) )
443
+ simulate_event ( :click , React . find_dom_node ( instance ) )
449
444
450
- expect ( element . refs [ :field ] . value ) . to eq ( "some_stuff" )
445
+ expect ( instance . refs [ :field ] . value ) . to eq ( "some_stuff" )
451
446
end
452
447
end
453
448
@@ -529,7 +524,7 @@ def render
529
524
530
525
expect ( Kernel ) . to receive ( :p ) . with ( "first" )
531
526
expect ( Kernel ) . to receive ( :p ) . with ( "second" )
532
- renderToDocument ( Foo )
527
+ render_to_document ( React . create_element ( Foo ) )
533
528
end
534
529
end
535
530
end
0 commit comments