hyper-react 0.10.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +26 -4
- data/Appraisals +3 -2
- data/CHANGELOG.md +19 -0
- data/README.md +3 -3
- data/config.ru +2 -1
- data/gemfiles/opal_0.10_react_13.gemfile +13 -0
- data/gemfiles/opal_0.10_react_14.gemfile +13 -0
- data/gemfiles/opal_0.10_react_15.gemfile +13 -0
- data/gemfiles/opal_0.8_react_15.gemfile +1 -1
- data/gemfiles/opal_0.9_react_15.gemfile +1 -1
- data/hyper-react.gemspec +1 -1
- data/lib/generators/reactive_ruby/test_app/templates/assets/javascripts/components.rb +0 -1
- data/lib/hyper-react.rb +2 -1
- data/lib/react/api.rb +3 -2
- data/lib/react/component/class_methods.rb +2 -2
- data/lib/react/component/props_wrapper.rb +2 -2
- data/lib/react/element.rb +1 -1
- data/lib/react/ext/opal-jquery/element.rb +26 -0
- data/lib/react/state.rb +6 -5
- data/lib/react/test/matchers/render_html_matcher.rb +5 -0
- data/lib/react/test/session.rb +14 -23
- data/lib/react/test/utils.rb +25 -0
- data/lib/react/top_level.rb +12 -28
- data/lib/react/top_level_render.rb +29 -0
- data/lib/reactive-ruby/isomorphic_helpers.rb +2 -2
- data/lib/reactive-ruby/version.rb +1 -1
- data/spec/index.html.erb +1 -0
- data/spec/react/children_spec.rb +1 -1
- data/spec/react/component/base_spec.rb +2 -2
- data/spec/react/component_spec.rb +74 -73
- data/spec/react/dsl_spec.rb +24 -21
- data/spec/react/element_spec.rb +7 -7
- data/spec/react/event_spec.rb +2 -2
- data/spec/react/native_library_spec.rb +20 -24
- data/spec/react/observable_spec.rb +36 -1
- data/spec/react/opal_jquery_extensions_spec.rb +48 -46
- data/spec/react/param_declaration_spec.rb +8 -8
- data/spec/react/react_spec.rb +41 -28
- data/spec/react/test/rspec_spec.rb +1 -1
- data/spec/react/test/session_spec.rb +8 -20
- data/spec/react/test/utils_spec.rb +11 -28
- data/spec/react/top_level_component_spec.rb +7 -2
- data/spec/react/tutorial/tutorial_spec.rb +2 -2
- data/spec/reactive-ruby/component_loader_spec.rb +10 -4
- data/spec/reactive-ruby/isomorphic_helpers_spec.rb +6 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/support/react/spec_helpers.rb +1 -21
- metadata +12 -6
data/lib/react/top_level.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require "native"
|
2
|
-
require 'active_support'
|
2
|
+
require 'active_support/core_ext/object/try'
|
3
3
|
require 'react/component/tags'
|
4
4
|
require 'react/component/base'
|
5
5
|
|
@@ -55,6 +55,12 @@ module React
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def self.render(element, container)
|
58
|
+
%x{
|
59
|
+
console.error(
|
60
|
+
"Warning: Using deprecated behavior of `React.render`,",
|
61
|
+
"require \"react/top_level_render\" to get the correct behavior."
|
62
|
+
);
|
63
|
+
}
|
58
64
|
container = `container.$$class ? container[0] : container`
|
59
65
|
if !(`typeof ReactDOM === 'undefined'`)
|
60
66
|
component = Native(`ReactDOM.render(#{element.to_n}, container, function(){#{yield if block_given?}})`) # v0.15+
|
@@ -69,6 +75,11 @@ module React
|
|
69
75
|
end
|
70
76
|
|
71
77
|
def self.is_valid_element(element)
|
78
|
+
%x{ console.error("Warning: `is_valid_element` is deprecated in favor of `is_valid_element?`."); }
|
79
|
+
element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})`
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.is_valid_element?(element)
|
72
83
|
element.kind_of?(React::Element) && `React.isValidElement(#{element.to_n})`
|
73
84
|
end
|
74
85
|
|
@@ -103,30 +114,3 @@ module React
|
|
103
114
|
end
|
104
115
|
|
105
116
|
end
|
106
|
-
|
107
|
-
Element.instance_eval do
|
108
|
-
def self.find(selector)
|
109
|
-
selector = begin
|
110
|
-
selector.dom_node
|
111
|
-
rescue
|
112
|
-
selector
|
113
|
-
end if `#{selector}.$dom_node !== undefined`
|
114
|
-
`$(#{selector})`
|
115
|
-
end
|
116
|
-
|
117
|
-
def self.[](selector)
|
118
|
-
find(selector)
|
119
|
-
end
|
120
|
-
|
121
|
-
define_method :render do |container = nil, params = {}, &block|
|
122
|
-
if `#{self.to_n}._reactrb_component_class === undefined`
|
123
|
-
`#{self.to_n}._reactrb_component_class = #{Class.new(React::Component::Base)}`
|
124
|
-
end
|
125
|
-
klass = `#{self.to_n}._reactrb_component_class`
|
126
|
-
klass.class_eval do
|
127
|
-
render(container, params, &block)
|
128
|
-
end
|
129
|
-
|
130
|
-
React.render(React.create_element(`#{self.to_n}._reactrb_component_class`), self)
|
131
|
-
end
|
132
|
-
end if Object.const_defined?('Element')
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module React
|
2
|
+
def self.render(element, container)
|
3
|
+
container = `container.$$class ? container[0] : container`
|
4
|
+
|
5
|
+
cb = %x{
|
6
|
+
function(){
|
7
|
+
setTimeout(function(){
|
8
|
+
#{yield if block_given?}
|
9
|
+
}, 0)
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
if !(`typeof ReactDOM === 'undefined'`)
|
14
|
+
native = `ReactDOM.render(#{element.to_n}, container, cb)` # v0.15+
|
15
|
+
elsif !(`typeof React.renderToString === 'undefined'`)
|
16
|
+
native = `React.render(#{element.to_n}, container, cb)`
|
17
|
+
else
|
18
|
+
raise "render is not defined. In React >= v15 you must import it with ReactDOM"
|
19
|
+
end
|
20
|
+
|
21
|
+
if `#{native}._getOpalInstance !== undefined`
|
22
|
+
`#{native}._getOpalInstance()`
|
23
|
+
elsif `React.findDOMNode !== undefined && #{native}.nodeType === undefined`
|
24
|
+
`React.findDOMNode(#{native})`
|
25
|
+
else
|
26
|
+
native
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -53,7 +53,7 @@ module React
|
|
53
53
|
end
|
54
54
|
else
|
55
55
|
def self.on_opal_server?
|
56
|
-
`typeof
|
56
|
+
`typeof Opal.global.document === 'undefined'`
|
57
57
|
end
|
58
58
|
|
59
59
|
def self.on_opal_client?
|
@@ -143,7 +143,7 @@ module React
|
|
143
143
|
def send_to_server(*args)
|
144
144
|
if IsomorphicHelpers.on_opal_server?
|
145
145
|
args_as_json = args.to_json
|
146
|
-
@result = [JSON.parse(`
|
146
|
+
@result = [JSON.parse(`Opal.global.ServerSideIsomorphicMethods[#{@name}](#{args_as_json})`)]
|
147
147
|
end
|
148
148
|
end
|
149
149
|
|
data/spec/index.html.erb
CHANGED
data/spec/react/children_spec.rb
CHANGED
@@ -25,8 +25,8 @@ RSpec.describe React::Component::Base, type: :component do
|
|
25
25
|
@instance_data.join(" ")
|
26
26
|
end
|
27
27
|
end
|
28
|
-
expect(Foo).to
|
29
|
-
expect(Bar).to
|
28
|
+
expect(Foo).to render_static_html("<span>working</span>")
|
29
|
+
expect(Bar).to render_static_html("<span>working well</span>")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -10,6 +10,9 @@ describe React::Component, type: :component do
|
|
10
10
|
stub_const 'Foo', Class.new
|
11
11
|
Foo.class_eval do
|
12
12
|
include React::Component
|
13
|
+
def initialize(native = nil)
|
14
|
+
end
|
15
|
+
|
13
16
|
def render
|
14
17
|
React.create_element('div')
|
15
18
|
end
|
@@ -31,6 +34,8 @@ describe React::Component, type: :component do
|
|
31
34
|
end
|
32
35
|
|
33
36
|
describe 'Life Cycle' do
|
37
|
+
let(:element_to_render) { React.create_element(Foo) }
|
38
|
+
|
34
39
|
before(:each) do
|
35
40
|
stub_const 'Foo', Class.new
|
36
41
|
Foo.class_eval do
|
@@ -51,7 +56,7 @@ describe React::Component, type: :component do
|
|
51
56
|
expect_any_instance_of(Foo).to receive(:bar)
|
52
57
|
expect_any_instance_of(Foo).to receive(:bar2)
|
53
58
|
|
54
|
-
|
59
|
+
React::Test::Utils.render_into_document(element_to_render)
|
55
60
|
end
|
56
61
|
|
57
62
|
it 'invokes `after_mount` registered methods when `componentDidMount()`' do
|
@@ -64,7 +69,7 @@ describe React::Component, type: :component do
|
|
64
69
|
expect_any_instance_of(Foo).to receive(:bar3)
|
65
70
|
expect_any_instance_of(Foo).to receive(:bar4)
|
66
71
|
|
67
|
-
|
72
|
+
React::Test::Utils.render_into_document(element_to_render)
|
68
73
|
end
|
69
74
|
|
70
75
|
it 'allows multiple class declared life cycle hooker' do
|
@@ -85,20 +90,18 @@ describe React::Component, type: :component do
|
|
85
90
|
|
86
91
|
expect_any_instance_of(Foo).to receive(:bar)
|
87
92
|
|
88
|
-
|
93
|
+
React::Test::Utils.render_into_document(element_to_render)
|
89
94
|
end
|
90
95
|
|
91
96
|
it 'allows block for life cycle callback' do
|
92
97
|
Foo.class_eval do
|
93
|
-
export_state(:foo)
|
94
|
-
|
95
98
|
before_mount do
|
96
|
-
foo
|
99
|
+
set_state({ foo: "bar" })
|
97
100
|
end
|
98
101
|
end
|
99
102
|
|
100
|
-
|
101
|
-
expect(
|
103
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
104
|
+
expect(instance.state[:foo]).to be('bar')
|
102
105
|
end
|
103
106
|
end
|
104
107
|
|
@@ -120,7 +123,7 @@ describe React::Component, type: :component do
|
|
120
123
|
end
|
121
124
|
end
|
122
125
|
|
123
|
-
expect(Foo).to
|
126
|
+
expect(Foo).to render_static_html('<div>bar</div>')
|
124
127
|
end
|
125
128
|
|
126
129
|
it 'allows kernal method names like "format" to be used as state variable names' do
|
@@ -131,7 +134,7 @@ describe React::Component, type: :component do
|
|
131
134
|
end
|
132
135
|
end
|
133
136
|
|
134
|
-
expect(Foo).to
|
137
|
+
expect(Foo).to render_static_html('<div>yes</div>')
|
135
138
|
end
|
136
139
|
|
137
140
|
it 'returns an observer with the bang method and no arguments' do
|
@@ -141,7 +144,7 @@ describe React::Component, type: :component do
|
|
141
144
|
end
|
142
145
|
end
|
143
146
|
|
144
|
-
expect(Foo).to
|
147
|
+
expect(Foo).to render_static_html('<div>React::Observable</div>')
|
145
148
|
end
|
146
149
|
|
147
150
|
it 'returns the current value of a state when written' do
|
@@ -152,7 +155,7 @@ describe React::Component, type: :component do
|
|
152
155
|
end
|
153
156
|
end
|
154
157
|
|
155
|
-
expect(Foo).to
|
158
|
+
expect(Foo).to render_static_html('<div>bar</div>')
|
156
159
|
end
|
157
160
|
|
158
161
|
it 'can access an explicitly defined state`' do
|
@@ -160,12 +163,14 @@ describe React::Component, type: :component do
|
|
160
163
|
define_state foo: :bar
|
161
164
|
end
|
162
165
|
|
163
|
-
expect(Foo).to
|
166
|
+
expect(Foo).to render_static_html('<div>bar</div>')
|
164
167
|
end
|
165
168
|
|
166
169
|
end
|
167
170
|
|
168
171
|
describe 'State setter & getter' do
|
172
|
+
let(:element_to_render) { React.create_element(Foo) }
|
173
|
+
|
169
174
|
before(:each) do
|
170
175
|
stub_const 'Foo', Class.new
|
171
176
|
Foo.class_eval do
|
@@ -185,8 +190,8 @@ describe React::Component, type: :component do
|
|
185
190
|
end
|
186
191
|
end
|
187
192
|
|
188
|
-
|
189
|
-
expect(
|
193
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
194
|
+
expect(instance.state.foo).to be('bar')
|
190
195
|
end
|
191
196
|
|
192
197
|
it 'defines init state by passing a block to `define_state`' do
|
@@ -194,8 +199,8 @@ describe React::Component, type: :component do
|
|
194
199
|
define_state(:foo) { 10 }
|
195
200
|
end
|
196
201
|
|
197
|
-
|
198
|
-
expect(
|
202
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
203
|
+
expect(instance.state.foo).to be(10)
|
199
204
|
end
|
200
205
|
|
201
206
|
it 'defines getter using `define_state`' do
|
@@ -207,8 +212,8 @@ describe React::Component, type: :component do
|
|
207
212
|
end
|
208
213
|
end
|
209
214
|
|
210
|
-
|
211
|
-
expect(
|
215
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
216
|
+
expect(instance.state.foo).to be(30)
|
212
217
|
end
|
213
218
|
|
214
219
|
it 'defines multiple state accessors by passing array to `define_state`' do
|
@@ -221,9 +226,9 @@ describe React::Component, type: :component do
|
|
221
226
|
end
|
222
227
|
end
|
223
228
|
|
224
|
-
|
225
|
-
expect(
|
226
|
-
expect(
|
229
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
230
|
+
expect(instance.state.foo).to be(10)
|
231
|
+
expect(instance.state.foo2).to be(20)
|
227
232
|
end
|
228
233
|
|
229
234
|
it 'invokes `define_state` multiple times to define states' do
|
@@ -232,29 +237,30 @@ describe React::Component, type: :component do
|
|
232
237
|
define_state(:foo2) { 40 }
|
233
238
|
end
|
234
239
|
|
235
|
-
|
236
|
-
expect(
|
237
|
-
expect(
|
240
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
241
|
+
expect(instance.state.foo).to be(30)
|
242
|
+
expect(instance.state.foo2).to be(40)
|
238
243
|
end
|
239
244
|
|
240
245
|
it 'can initialize multiple state variables with a block' do
|
241
246
|
Foo.class_eval do
|
242
247
|
define_state(:foo, :foo2) { 30 }
|
243
248
|
end
|
244
|
-
|
245
|
-
|
246
|
-
expect(
|
249
|
+
|
250
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
251
|
+
expect(instance.state.foo).to be(30)
|
252
|
+
expect(instance.state.foo2).to be(30)
|
247
253
|
end
|
248
254
|
|
249
255
|
it 'can mix multiple state variables with initializers and a block' do
|
250
256
|
Foo.class_eval do
|
251
257
|
define_state(:x, :y, foo: 1, bar: 2) {3}
|
252
258
|
end
|
253
|
-
|
254
|
-
expect(
|
255
|
-
expect(
|
256
|
-
expect(
|
257
|
-
expect(
|
259
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
260
|
+
expect(instance.state.x).to be(3)
|
261
|
+
expect(instance.state.y).to be(3)
|
262
|
+
expect(instance.state.foo).to be(1)
|
263
|
+
expect(instance.state.bar).to be(2)
|
258
264
|
end
|
259
265
|
|
260
266
|
it 'gets state in render method' do
|
@@ -265,8 +271,8 @@ describe React::Component, type: :component do
|
|
265
271
|
end
|
266
272
|
end
|
267
273
|
|
268
|
-
|
269
|
-
expect(
|
274
|
+
instance = React::Test::Utils.render_into_document(element_to_render)
|
275
|
+
expect(`#{instance.dom_node}.textContent`).to eq('10')
|
270
276
|
end
|
271
277
|
|
272
278
|
it 'supports original `setState` as `set_state` method' do
|
@@ -276,8 +282,8 @@ describe React::Component, type: :component do
|
|
276
282
|
end
|
277
283
|
end
|
278
284
|
|
279
|
-
|
280
|
-
expect(
|
285
|
+
instance = renderToDocument(Foo)
|
286
|
+
expect(instance.state[:foo]).to be('bar')
|
281
287
|
end
|
282
288
|
|
283
289
|
it 'supports original `replaceState` as `set_state!` method' do
|
@@ -289,8 +295,8 @@ describe React::Component, type: :component do
|
|
289
295
|
end
|
290
296
|
|
291
297
|
element = renderToDocument(Foo)
|
292
|
-
expect(element.state
|
293
|
-
expect(element.state
|
298
|
+
expect(element.state[:foo]).to be_nil
|
299
|
+
expect(element.state[:bar]).to eq('lorem')
|
294
300
|
end
|
295
301
|
|
296
302
|
it 'supports original `state` method' do
|
@@ -304,7 +310,7 @@ describe React::Component, type: :component do
|
|
304
310
|
end
|
305
311
|
end
|
306
312
|
|
307
|
-
expect(Foo).to
|
313
|
+
expect(Foo).to render_static_html('<div>bar</div>')
|
308
314
|
end
|
309
315
|
|
310
316
|
it 'transforms state getter to Ruby object' do
|
@@ -320,7 +326,7 @@ describe React::Component, type: :component do
|
|
320
326
|
end
|
321
327
|
end
|
322
328
|
|
323
|
-
expect(Foo).to
|
329
|
+
expect(Foo).to render_static_html('<div>Hello</div>')
|
324
330
|
end
|
325
331
|
end
|
326
332
|
|
@@ -341,7 +347,7 @@ describe React::Component, type: :component do
|
|
341
347
|
end
|
342
348
|
|
343
349
|
element = renderToDocument(Foo, prop: 'foobar')
|
344
|
-
expect(
|
350
|
+
expect(`#{element.dom_node}.textContent`).to eq('foobar')
|
345
351
|
end
|
346
352
|
|
347
353
|
it 'accesses nested params as orignal Ruby object' do
|
@@ -352,7 +358,7 @@ describe React::Component, type: :component do
|
|
352
358
|
end
|
353
359
|
|
354
360
|
element = renderToDocument(Foo, prop: [{foo: 10}])
|
355
|
-
expect(
|
361
|
+
expect(`#{element.dom_node}.textContent`).to eq('10')
|
356
362
|
end
|
357
363
|
end
|
358
364
|
|
@@ -383,9 +389,9 @@ describe React::Component, type: :component do
|
|
383
389
|
end
|
384
390
|
end
|
385
391
|
|
386
|
-
|
387
|
-
|
388
|
-
expect(
|
392
|
+
instance = renderToDocument(Foo, {foo: 10})
|
393
|
+
instance.set_props!(bar: 20)
|
394
|
+
expect(`#{instance.dom_node}.innerHTML`).to eq('null')
|
389
395
|
end
|
390
396
|
end
|
391
397
|
|
@@ -470,8 +476,8 @@ describe React::Component, type: :component do
|
|
470
476
|
end
|
471
477
|
end
|
472
478
|
|
473
|
-
expect(Foo).to
|
474
|
-
expect(Foo).to
|
479
|
+
expect(Foo).to render_static_html('<div>lorem-bar</div>').with_params(foo: 'lorem')
|
480
|
+
expect(Foo).to render_static_html('<div>foo-bar</div>')
|
475
481
|
end
|
476
482
|
end
|
477
483
|
end
|
@@ -567,8 +573,8 @@ describe React::Component, type: :component do
|
|
567
573
|
end
|
568
574
|
|
569
575
|
element = React.create_element(Foo)
|
570
|
-
instance =
|
571
|
-
|
576
|
+
instance = React::Test::Utils.render_into_document(element)
|
577
|
+
React::Test::Utils.simulate(:click, instance)
|
572
578
|
expect(instance.state.clicked).to eq(true)
|
573
579
|
end
|
574
580
|
|
@@ -587,7 +593,7 @@ describe React::Component, type: :component do
|
|
587
593
|
|
588
594
|
expect { |b|
|
589
595
|
element = React.create_element(Foo).on(:foo_submit, &b)
|
590
|
-
|
596
|
+
React::Test::Utils.render_into_document(element)
|
591
597
|
}.to yield_with_args('bar')
|
592
598
|
end
|
593
599
|
|
@@ -606,7 +612,7 @@ describe React::Component, type: :component do
|
|
606
612
|
|
607
613
|
expect { |b|
|
608
614
|
element = React.create_element(Foo).on(:foo_invoked, &b)
|
609
|
-
|
615
|
+
React::Test::Utils.render_into_document(element)
|
610
616
|
}.to yield_with_args([1,2,3], 'bar')
|
611
617
|
end
|
612
618
|
end
|
@@ -626,8 +632,8 @@ describe React::Component, type: :component do
|
|
626
632
|
end
|
627
633
|
end
|
628
634
|
|
629
|
-
|
630
|
-
expect(
|
635
|
+
instance = renderToDocument(Foo)
|
636
|
+
expect(instance.refs[:field]).not_to be_nil
|
631
637
|
end
|
632
638
|
|
633
639
|
it 'accesses refs through `refs` method' do
|
@@ -639,16 +645,15 @@ describe React::Component, type: :component do
|
|
639
645
|
end
|
640
646
|
end
|
641
647
|
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
expect(element.refs.field.value).to eq('some_stuff')
|
648
|
+
instance = React::Test::Utils.render_into_document(React.create_element(Foo))
|
649
|
+
React::Test::Utils.simulate(:click, instance)
|
650
|
+
expect(instance.refs[:field].value).to eq('some_stuff')
|
646
651
|
end
|
647
652
|
|
648
|
-
it "allows access the actual DOM node" do
|
653
|
+
it "allows access the actual DOM node", v13_exclude: true do
|
649
654
|
Foo.class_eval do
|
650
655
|
after_mount do
|
651
|
-
dom = refs[:my_div].
|
656
|
+
dom = refs[:my_div].to_n
|
652
657
|
`dom.innerHTML = 'Modified'`
|
653
658
|
end
|
654
659
|
|
@@ -685,7 +690,7 @@ describe React::Component, type: :component do
|
|
685
690
|
end
|
686
691
|
end
|
687
692
|
|
688
|
-
expect(Bar).to
|
693
|
+
expect(Bar).to render_static_html('<div><div><span>astring</span></div></div>')
|
689
694
|
end
|
690
695
|
|
691
696
|
it 'builds single node in top-level render without providing a block' do
|
@@ -698,7 +703,7 @@ describe React::Component, type: :component do
|
|
698
703
|
end
|
699
704
|
end
|
700
705
|
|
701
|
-
expect(Foo).to
|
706
|
+
expect(Foo).to render_static_html('<div></div>')
|
702
707
|
end
|
703
708
|
|
704
709
|
it 'redefines `p` to make method missing work' do
|
@@ -716,7 +721,7 @@ describe React::Component, type: :component do
|
|
716
721
|
end
|
717
722
|
|
718
723
|
markup = '<p class="foo"><p></p><div>lorem ipsum</div><p id="10"></p></p>'
|
719
|
-
expect(Foo).to
|
724
|
+
expect(Foo).to render_static_html(markup)
|
720
725
|
end
|
721
726
|
|
722
727
|
it 'only overrides `p` in render context' do
|
@@ -766,7 +771,7 @@ describe React::Component, type: :component do
|
|
766
771
|
Foo.define_method :needs_update? do |next_params, next_state|
|
767
772
|
next_params.changed?
|
768
773
|
end
|
769
|
-
@foo = Foo.new
|
774
|
+
@foo = Foo.new(nil)
|
770
775
|
end
|
771
776
|
|
772
777
|
it "returns false if new and old params are the same" do
|
@@ -794,7 +799,7 @@ describe React::Component, type: :component do
|
|
794
799
|
Foo.define_method :needs_update? do |next_params, next_state|
|
795
800
|
next_state.changed?
|
796
801
|
end
|
797
|
-
@foo = Foo.new
|
802
|
+
@foo = Foo.new(nil)
|
798
803
|
end
|
799
804
|
|
800
805
|
it "returns false if both new and old states are empty" do
|
@@ -837,10 +842,6 @@ describe React::Component, type: :component do
|
|
837
842
|
stub_const 'Foo', Class.new
|
838
843
|
Foo.class_eval do
|
839
844
|
include React::Component
|
840
|
-
export_state :the_children
|
841
|
-
before_mount do
|
842
|
-
the_children! children
|
843
|
-
end
|
844
845
|
def render
|
845
846
|
React.create_element('div') { 'lorem' }
|
846
847
|
end
|
@@ -851,9 +852,9 @@ describe React::Component, type: :component do
|
|
851
852
|
ele = React.create_element(Foo) {
|
852
853
|
[React.create_element('a'), React.create_element('li')]
|
853
854
|
}
|
854
|
-
|
855
|
+
instance = React::Test::Utils.render_into_document(ele)
|
855
856
|
|
856
|
-
children =
|
857
|
+
children = instance.children
|
857
858
|
|
858
859
|
expect(children).to be_a(React::Children)
|
859
860
|
expect(children.count).to eq(2)
|
@@ -862,8 +863,8 @@ describe React::Component, type: :component do
|
|
862
863
|
|
863
864
|
it 'returns an empty Enumerator if there are no children' do
|
864
865
|
ele = React.create_element(Foo)
|
865
|
-
|
866
|
-
nodes =
|
866
|
+
instance = React::Test::Utils.render_into_document(ele)
|
867
|
+
nodes = instance.children.each
|
867
868
|
expect(nodes.size).to eq(0)
|
868
869
|
expect(nodes.count).to eq(0)
|
869
870
|
end
|