Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test loading message content before AJAX request is completed with Capybara

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!

like image 819
Chris Butler Avatar asked Oct 05 '22 19:10

Chris Butler


1 Answers

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')

like image 177
Chris Butler Avatar answered Oct 10 '22 02:10

Chris Butler