Skip to content
This repository was archived by the owner on Oct 19, 2018. It is now read-only.

Commit 4b86d72

Browse files
committed
Migrate tests to use render_static_html matcher
1 parent c81398b commit 4b86d72

File tree

6 files changed

+52
-52
lines changed

6 files changed

+52
-52
lines changed

spec/react/dsl_spec.rb

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
require 'spec_helper'
22

33
if opal?
4-
describe 'the React DSL' do
4+
describe 'the React DSL', type: :component do
55

66
context "render macro" do
77

@@ -14,7 +14,7 @@
1414
end
1515
end
1616

17-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div class="foo">hello</div>')
17+
expect(Foo).to render_static_html('<div class="foo">hello</div>')
1818
end
1919

2020
it "can define the render method with the render macro without a container" do
@@ -26,7 +26,7 @@
2626
end
2727
end
2828

29-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>hello</span>')
29+
expect(Foo).to render_static_html('<span>hello</span>')
3030
end
3131

3232
it "can define the render method with the render macro with a application defined container" do
@@ -40,7 +40,7 @@
4040
render Bar, p1: "fred"
4141
end
4242

43-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>hello fred</span>')
43+
expect(Foo).to render_static_html('<span>hello fred</span>')
4444
end
4545
end
4646

@@ -53,7 +53,7 @@ def render
5353
end
5454
end
5555

56-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>')
56+
expect(Foo).to render_static_html('<div>hello</div>')
5757
end
5858

5959
it "will pass converted props through event handlers" do
@@ -77,7 +77,7 @@ def render
7777
end
7878
end
7979

80-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>hello</div>')
80+
expect(Foo).to render_static_html('<div>hello</div>')
8181
end
8282

8383
it "has a .span short hand String method" do
@@ -89,7 +89,7 @@ def render
8989
end
9090
end
9191

92-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><span>hello</span><span>goodby</span></div>')
92+
expect(Foo).to render_static_html('<div><span>hello</span><span>goodby</span></div>')
9393
end
9494

9595
it "has a .br short hand String method" do
@@ -113,7 +113,7 @@ def render
113113
end
114114
end
115115

116-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<table><tr><td>hello</td></tr></table>')
116+
expect(Foo).to render_static_html('<table><tr><td>hello</td></tr></table>')
117117
end
118118

119119
it "has a .para short hand String method" do
@@ -125,7 +125,7 @@ def render
125125
end
126126
end
127127

128-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div><p>hello</p></div>')
128+
expect(Foo).to render_static_html('<div><p>hello</p></div>')
129129
end
130130

131131
it 'can do a method call on a class name that is not a direct sibling' do
@@ -141,8 +141,8 @@ def render
141141
Comp()
142142
end
143143
end
144-
expect(React.render_to_static_markup(React.create_element(Mod::NestedMod::NestedComp)))
145-
.to eq('<span>Mod::Comp</span>')
144+
expect(Mod::NestedMod::NestedComp)
145+
.to render_static_html('<span>Mod::Comp</span>')
146146
end
147147

148148
it 'raises a meaningful error if a Constant Name is not actually a component' do
@@ -187,7 +187,7 @@ def render
187187
end
188188
end
189189

190-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span>a man walks into a bar</span>')
190+
expect(Foo).to render_static_html('<span>a man walks into a bar</span>')
191191
end
192192

193193
it "can add class names by the haml .class notation" do
@@ -206,7 +206,7 @@ def render
206206
end
207207
end
208208

209-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="other-class the-class">a man walks into a bar</span>')
209+
expect(Foo).to render_static_html('<span class="other-class the-class">a man walks into a bar</span>')
210210
end
211211

212212
it "can use the 'class' keyword for classes" do
@@ -218,7 +218,7 @@ def render
218218
end
219219
end
220220

221-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span class="the-class">hello</span>')
221+
expect(Foo).to render_static_html('<span class="the-class">hello</span>')
222222
end
223223

224224
it "can generate a unrendered node using the .as_node method" do # div { "hello" }.as_node
@@ -230,7 +230,8 @@ def render
230230
end
231231
end
232232

233-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<span data-size="12">React::Element</span>')
233+
expect(Foo)
234+
.to render_static_html('<span data-size="12">React::Element</span>')
234235
end
235236

236237
it "can use the dangerously_set_inner_HTML param" do
@@ -242,7 +243,7 @@ def render
242243
end
243244
end
244245

245-
expect(React.render_to_static_markup(React.create_element(Foo))).to eq('<div>Hello&nbsp;&nbsp;Goodby</div>')
246+
expect(Foo).to render_static_html('<div>Hello&nbsp;&nbsp;Goodby</div>')
246247
end
247248

248249
it 'should convert a hash param to hyphenated html attributes if in React::HASH_ATTRIBUTES' do
@@ -254,8 +255,8 @@ def render
254255
end
255256
end
256257

257-
expect(React.render_to_static_markup(React.create_element(Foo)))
258-
.to eq('<div data-foo="bar" aria-foo-bar="foo"></div>')
258+
expect(Foo)
259+
.to render_static_html('<div data-foo="bar" aria-foo-bar="foo"></div>')
259260
end
260261

261262
it 'should not convert a hash param to hyphenated html attributes if not in React::HASH_ATTRIBUTES' do
@@ -267,8 +268,10 @@ def render
267268
end
268269
end
269270

270-
expect(React.render_to_static_markup(React.create_element(Foo)))
271-
.to eq('<div title="{&quot;bar&quot;=&gt;&quot;foo&quot;}"></div>')
271+
expect(Foo)
272+
.to render_static_html(
273+
'<div title="{&quot;bar&quot;=&gt;&quot;foo&quot;}"></div>'
274+
)
272275
end
273276

274277
it "will remove all elements passed as params from the rendering buffer" do
@@ -290,7 +293,7 @@ def render
290293
end
291294
end
292295

293-
expect(React.render_to_static_markup(React.create_element(Test))).to eq('<div><b>hello</b><b>hello</b></div>')
296+
expect(Test).to render_static_html('<div><b>hello</b><b>hello</b></div>')
294297
end
295298
end
296299
end

spec/react/element_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
if opal?
44
# require 'reactrb/new-event-name-convention' # this require will get rid of any error messages but
55
# the on method will no longer attach to the param prefixed with _on
6-
describe React::Element do
6+
describe React::Element, type: :component do
77
it 'bridges `type` of native React.Element attributes' do
88
element = React.create_element('div')
99
expect(element.element_type).to eq("div")

spec/react/native_library_spec.rb

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class NestedComponent < React::Component::Base
1717
end
1818
end
1919

20-
describe "React::NativeLibrary" do
20+
describe "React::NativeLibrary", type: :component do
2121

2222
after(:each) do
2323
%x{
@@ -52,8 +52,7 @@ class NestedComponent < React::Component::Base
5252
Foo.class_eval do
5353
imports "NativeLibrary.FunctionalComponent"
5454
end
55-
expect(React.render_to_static_markup(
56-
React.create_element(Foo, name: "There"))).to eq('<div>Hello There</div>')
55+
expect(Foo).to render_static_html('<div>Hello There</div>').with_params(name: "There")
5756
end
5857
end
5958

@@ -87,8 +86,8 @@ class NestedComponent < React::Component::Base
8786
Foo.class_eval do
8887
imports "NativeLibrary"
8988
end
90-
expect(React.render_to_static_markup(
91-
React.create_element(Foo::NativeComponent, name: "There"))).to eq('<div>Hello There</div>')
89+
expect(Foo::NativeComponent)
90+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
9291
end
9392

9493
it "will import a nested React.js library into the Ruby name space" do
@@ -107,8 +106,8 @@ class NestedComponent < React::Component::Base
107106
Foo.class_eval do
108107
imports "NativeLibrary"
109108
end
110-
expect(React.render_to_static_markup(
111-
React.create_element(Foo::NestedLibrary::NativeComponent, name: "There"))).to eq('<div>Hello There</div>')
109+
expect(Foo::NestedLibrary::NativeComponent)
110+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
112111
end
113112

114113
it "will rename an imported a React.js component" do
@@ -127,8 +126,8 @@ class NestedComponent < React::Component::Base
127126
imports "NativeLibrary"
128127
rename "NativeComponent" => "Bar"
129128
end
130-
expect(React.render_to_static_markup(
131-
React.create_element(Foo::Bar, name: "There"))).to eq('<div>Hello There</div>')
129+
expect(Foo::Bar)
130+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
132131
end
133132

134133
it "will give a reasonable error when failing to import a renamed component" do
@@ -164,8 +163,8 @@ class NestedComponent < React::Component::Base
164163
Foo.class_eval do
165164
imports "NativeComponent"
166165
end
167-
expect(React.render_to_static_markup(
168-
React.create_element(Foo, name: "There"))).to eq('<div>Hello There</div>')
166+
expect(Foo)
167+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
169168

170169
end
171170

@@ -184,8 +183,8 @@ class NestedComponent < React::Component::Base
184183
Foo.class_eval do
185184
imports "NativeLibrary.NativeComponent"
186185
end
187-
expect(React.render_to_static_markup(
188-
React.create_element(Foo, name: "There"))).to eq('<div>Hello There</div>')
186+
expect(Foo)
187+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
189188

190189
end
191190

@@ -234,8 +233,7 @@ class NestedComponent < React::Component::Base
234233
}
235234
})
236235
}
237-
expect(React.render_to_static_markup(
238-
React.create_element(Foo))).to eq('<div>Hello There</div>')
236+
expect(Foo).to render_static_html('<div>Hello There</div>')
239237
end
240238

241239
it 'will automatically import a React.js component when referenced in another component with the _as_node suffix' do
@@ -254,8 +252,7 @@ class NestedComponent < React::Component::Base
254252
}
255253
})
256254
}
257-
expect(React.render_to_static_markup(
258-
React.create_element(Foo))).to eq('<div><div>Hello There</div><div>Hello There</div></div>')
255+
expect(Foo).to render_static_html('<div><div>Hello There</div><div>Hello There</div></div>')
259256
end
260257

261258
it "will automatically import a React.js component in a library when referenced in another component with the _as_node suffix" do
@@ -276,8 +273,7 @@ class NestedComponent < React::Component::Base
276273
})
277274
}
278275
}
279-
expect(React.render_to_static_markup(
280-
React.create_element(Foo))).to eq('<div><div>Hello There</div><div>Hello There</div></div>')
276+
expect(Foo).to render_static_html('<div><div>Hello There</div><div>Hello There</div></div>')
281277
end
282278

283279
it "will automatically import a React.js component when referenced as a constant" do
@@ -289,8 +285,8 @@ class NestedComponent < React::Component::Base
289285
}
290286
})
291287
}
292-
expect(React.render_to_static_markup(
293-
React.create_element(NativeComponent, name: "There"))).to eq('<div>Hello There</div>')
288+
expect(NativeComponent)
289+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
294290
end
295291

296292
it "will automatically import a native library containing a React.js component" do
@@ -322,8 +318,8 @@ class NestedComponent < React::Component::Base
322318
})
323319
}
324320
}
325-
expect(React.render_to_static_markup(
326-
React.create_element(NativeLibrary::NativeComponent, name: "There"))).to eq('<div>Hello There</div>')
321+
expect(NativeLibrary::NativeComponent)
322+
.to render_static_html('<div>Hello There</div>').with_params(name: "There")
327323
end
328324

329325
it "will produce a sensible error if the component is not in the library" do

spec/react/param_declaration_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ def render
190190
"#{params.foo.kind}"
191191
end
192192
end
193-
expect(React.render_to_static_markup(React.create_element(Foo, foo: {bazwoggle: 1}))).to eq('<span>2</span>')
193+
expect(Foo).to render_static_html('<span>2</span>').with_params(foo: {bazwoggle: 1})
194194
end
195195

196196
it "even if contains an embedded native object" do

spec/react/top_level_component_spec.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ def render
3939
end
4040

4141
def render_top_level(controller, component_name)
42-
render_to_html(React::TopLevelRailsComponent, controller: controller,
43-
component_name: component_name, render_params: {})
42+
params = {
43+
controller: controller,
44+
component_name: component_name,
45+
render_params: {}
46+
}
47+
element = React.create_element(React::TopLevelRailsComponent, params)
48+
React.render_to_static_markup(element)
4449
end
4550

4651
describe React::TopLevelRailsComponent do

spec/support/react/spec_helpers.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ module React
33
module SpecHelpers
44
`var ReactTestUtils = React.addons.TestUtils`
55

6-
def render_to_html(type, options = {})
7-
element = React.create_element(type, options)
8-
React.render_to_static_markup(element)
9-
end
106

117
def renderToDocument(type, options = {})
128
element = React.create_element(type, options)

0 commit comments

Comments
 (0)