Last Updated: February 25, 2016
· bookwyrm

Testing AJAX with Poltergeist - Processing as JS but HTML rendered

I was testing some some AJAX in qatab today and ran into an odd situation - Rails was recognizing a request as a JS request, but it was rendering the HTML template, not the JS template. This worked just fine in my development environment when testing by hand, but when testing with Capybara and Poltergeist I was seeing the odd behavior. After much Googling, headshaking and testing different things, I hit upon something that worked.

I thought that maybe my test was running "too fast" and that Poltergeist wasn't waiting for the AJAX to finish. I added some code to make sure that the request completed:

find('#AddNoteForm').should_not be_visible

Only, this wasn't working - my test was still failing because Rails was rendering the HTML template. After some more digging, I changed my code up to use a different check:

page.should have_css('#AddNoteForm', visible: false)

And, all of a sudden it started working as I expected.

I don't know why it behaves differently, but if you're having an issue where Rails is processing as JS but rendering HTML, try to change up your check.

Say Thanks

1 Response
Add your response

74ce82b907925c1c76f9d9a737d4c685 normal

have_css('#whatever', visible: false) means "include visible things when finding"

over 1 year ago ·