I have a remote form, which disables the submit button while the AJAX request is in progress. I'd like to check that if I stress click the button, no other AJAX requests will be done. How could I check this in an integration test?
you can check active ajax calls with jquery
$.active
If you use capybara for integration tests
page.evaluate_script('$.active').should be <= 1
might be a solution.
As you probably don't know when calls occur a helper function might do the trick
def test_until(seconds=5)
start_time = Time.now
while (Time.now - start_time) <= seconds do
yield
sleep 0.05
end
end
wich can be called like this
test_until do
page.evaluate_script('$.active').should be <= 1
end
Thus you test for 5 seconds if there are ever more than one active ajax call
Keep a global or a static variable. Increment the variable inside the function called by Ajax and check what will be the value of your variable. It should never exceed one, guaranteeing that Ajax call is made only once.
If you are onto automated testing, this provides you more info on checking number of ajax calls active and other stuffs.
http://hedleyproctor.com/2012/07/effective-selenium-testing/
Hope this helps. Thank you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With