Skip to content

Commit 0b9c0ec

Browse files
committed
Simplify assertion of non-prerendered react component
1 parent 1c1fa5b commit 0b9c0ec

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

test/dummy/app/controllers/server_controller.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ def console_example_suppressed
1616
end
1717

1818
def inline_component_prerender_true
19-
render component: 'TodoList',
20-
props: { todos: ['Render this inline'] },
21-
tag: 'span',
22-
class: 'custom-class',
23-
id: 'custom-id',
24-
data: { remote: true }
19+
render(component_options)
2520
end
2621

2722
def inline_component_prerender_false
28-
render component: 'TodoList',
29-
props: { todos: ['Render this inline'] },
30-
tag: 'span',
31-
class: 'custom-class',
32-
id: 'custom-id',
33-
data: { remote: true },
34-
prerender: false
23+
render(component_options.merge(prerender: false))
24+
end
25+
26+
private
27+
28+
def component_options
29+
{
30+
component: 'TodoList',
31+
props: { todos: ['Render this inline'] },
32+
tag: 'span',
33+
class: 'custom-class',
34+
id: 'custom-id',
35+
data: { remote: true }
36+
}
3537
end
3638
end

test/server_rendered_html_test.rb

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,8 @@ def wait_to_ensure_asset_pipeline_detects_changes
7171
test 'react inline component rendering (not pre-rendered)' do
7272
get '/server/inline_component_prerender_false'
7373
rendered_html = response.body
74-
75-
assert_match(/<span.*data-react-class=\"TodoList\"/, rendered_html)
76-
# make sure that the items are prerendered
77-
assert_match(/Render this inline/, rendered_html)
78-
assert_match(/<\/span>/, rendered_html, "it accepts a tag override")
79-
# make sure that the layout is rendered with the component
80-
assert_match(/<title>Dummy<\/title>/, rendered_html)
81-
# make sure that custom html attributes are rendered
82-
assert_match(/class=\"custom-class\"/, rendered_html)
83-
assert_match(/id=\"custom-id\"/, rendered_html)
84-
assert_match(/data-remote=\"true\"/, rendered_html)
74+
# make sure the tag closes immediately:
75+
assert_match(/<span.*data-react-class=\"TodoList\"[^<]*><\/span>/, rendered_html)
8576
end
8677
end
8778
end

0 commit comments

Comments
 (0)