5

I see a lot of questions and answers about Capybara not waiting for an AJAX request to complete before testing for content, but I need to do the opposite: I want to test that a loading message is present before the AJAX request is done.

How would I check content is shown before an AJAX request is done with Capybara in RSpec?

Thanks!

Chris Butler
  • 733
  • 6
  • 23

1 Answers1

4

I figured it out...

If you want to check something right away without waiting for AJAX to finish, you just check the text with an include:

page.find('#id').text.should include('loading...')

If you do want to wait for AJAX to return you use have_content:

page.find('#id').should have_content('loaded')

Chris Butler
  • 733
  • 6
  • 23