Skip to content

Fix/assert react component with multiple case #974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/react/rails/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ module TestHelper
# assert_equal "Hello world", props[:message]
# end
def assert_react_component(name)
assert_select "div[data-react-class]" do |dom|
assert_select "[data-react-class=?]", name

assert_select "div[data-react-class=?]", name do |dom|
if block_given?
props = JSON.parse(dom.attr("data-react-props"))
props.deep_transform_keys! { |key| key.to_s.underscore }
Expand Down
2 changes: 1 addition & 1 deletion lib/react/server_rendering/webpacker_manifest_container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def file_path path
end
elsif MAJOR >= 3
def file_path path
::Rails.root.join('public', manifest.lookup(path)[1..-1])
::Rails.root.join('public', manifest.lookup!(path)[1..-1])
end
else # 1.0 and 1.1 support
def file_path path
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
},
"devDependencies": {
"webpack": "^2.3.3"
},
"dependencies": {
"react_ujs": "^2.4.4"
}
}
2 changes: 1 addition & 1 deletion test/dummy_webpacker1/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</ul>

<div id='component-parent'>
<%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %>
<%= react_component 'GreetingMessage', { name: @name, last_name: "Last #{@name}", info: { name: @name } }, { id: 'component', class: "greeting-message", prerender: @prerender } %>
<ul>
<%= react_component 'Todo', { todo: 'Another Component' }, { id: 'todo', prerender: @prerender } %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion test/dummy_webpacker2/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</ul>

<div id='component-parent'>
<%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %>
<%= react_component 'GreetingMessage', { name: @name, last_name: "Last #{@name}", info: { name: @name } }, { id: 'component', class: "greeting-message", prerender: @prerender } %>
<ul>
<%= react_component 'Todo', { todo: 'Another Component' }, { id: 'todo', prerender: @prerender } %>
</ul>
Expand Down
2 changes: 1 addition & 1 deletion test/dummy_webpacker3/app/views/pages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</ul>

<div id='component-parent'>
<%= react_component 'GreetingMessage', { name: @name }, { id: 'component', prerender: @prerender } %>
<%= react_component 'GreetingMessage', { name: @name, last_name: "Last #{@name}", info: { name: @name } }, { id: 'component', class: "greeting-message", prerender: @prerender } %>
<ul>
<%= react_component 'Todo', { todo: 'Another Component' }, { id: 'todo', prerender: @prerender } %>
</ul>
Expand Down
7 changes: 7 additions & 0 deletions test/react/rails/test_helper_test.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
require 'test_helper'

class TestHelperTest < ActionDispatch::IntegrationTest
setup do
WebpackerHelpers.compile_if_missing
end

test 'assert_react_component' do
get "/pages/1"
assert_equal 200, response.status
Expand All @@ -13,5 +17,8 @@ class TestHelperTest < ActionDispatch::IntegrationTest
assert_select "[id=?]", "component"
assert_select "[class=?]", "greeting-message"
end
assert_react_component "Todo" do |props|
assert_equal "Another Component", props[:todo]
end
end
end
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,11 @@ rc@^1.1.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react_ujs@^2.4.4:
version "2.4.4"
resolved "https://registry.yarnpkg.com/react_ujs/-/react_ujs-2.4.4.tgz#49bac535d24024a96b0a35d7514d18188aea42bc"
integrity sha512-RON6mgV+I3s6KkmvxTQi+WGuoLbhZ+TzRat06EE/RHFvzU+Na1Eom6XnesQeOP7WCrTZGOdcZEPP0P7QrJrHfg==

read-pkg-up@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02"
Expand Down