Skip to content

Add assert_react_component method for test react_component render result #957

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 1 commit into from
Jan 4, 2019
Merged

Add assert_react_component method for test react_component render result #957

merged 1 commit into from
Jan 4, 2019

Conversation

huacnlee
Copy link
Contributor

@huacnlee huacnlee commented Jan 2, 2019

test 'assert_react_component' do
  get "/pages/1"
  assert_equal 200, response.status
  assert_react_component "GreetingMessage"
  assert_react_component "GreetingMessage" do |props|
    assert_equal "Bob", props[:name]
    assert_equal "Last Bob", props[:last_name]
    assert_equal "Bob", props[:info][:name]

    assert_select "[id=?]", "component"
    assert_select "[class=?]", "greeting-message"
  end
end

@huacnlee huacnlee changed the title Add assert_react_component method helper for test react_component ren… Add assert_react_component method for test react_component render result Jan 2, 2019
Copy link
Member

@BookOfGreg BookOfGreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a wonderful submission, well written and useful.
Thank you for the contribution!
I have a couple comments that might be able to improve it further and I'd welcome your thoughts on those points.

@BookOfGreg
Copy link
Member

BookOfGreg commented Jan 3, 2019

This is good work. I will need to look into why the tests are failing before merge, based on the current Travis-ci run 1505 and 1506 but then OK to merge.

Edit:
Looks like the first set of failures in 1505 is maybe scope related, the ones in 1506 maybe a problem with the autoloader in different rails versions. I may be able to look into this later as I recognise that the test suite for this gem can be quite complex at times.

@huacnlee
Copy link
Contributor Author

huacnlee commented Jan 4, 2019

@BookOfGreg ActiveSupport.on_load(:action_dispatch_integration_test) was coming from Rails 5.0.0, so 4.2 not support that.

See here example of ActionMailer:

rails/rails@9a64293

How a about here change to:

ActiveSupport.on_load(:action_view) do
  include ::React::Rails::ViewHelper
  ActionDispatch::IntegrationTest.send :include, React::Rails::TestHelper
end

@BookOfGreg
Copy link
Member

If it's good enough for Rails, it's good enough for me :) I'll accept that suggestion.

@huacnlee
Copy link
Contributor Author

huacnlee commented Jan 4, 2019

@BookOfGreg just updated

@BookOfGreg BookOfGreg merged commit a3489eb into reactjs:master Jan 4, 2019
@BookOfGreg
Copy link
Member

I'll clean up whatever is wrong with the test suite. Thank you for the contribution. I'll try get a release out in the coming weeks.

@huacnlee huacnlee deleted the add-assert-method-for-test branch April 1, 2019 02:35
@BookOfGreg BookOfGreg mentioned this pull request May 12, 2019
4 tasks
@cacods
Copy link

cacods commented Mar 10, 2021

Is it possible to use assert_react_components for components inside the main component called with render_component helper?

@eelkevdbos
Copy link

@cacods, I expect you need a feature test for this because it would involve actually initializing the server rendered dom elements into full react components.

The current assert_react_components helper does only asserts the existence of a div[data-react-class=?] with the expected properties through inspection of the data-react-props attribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants