Created
February 10, 2016 15:22
-
-
Save KBalderson/06d26af1f868e4bc2911 to your computer and use it in GitHub Desktop.
Wait for angular (1.x) http requests to finish, based in part, on thoughtbot's approach to jQuery ajax requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# features/support/wait_for_angular.rb | |
module WaitForAngularSync | |
def wait_for_angular_sync | |
Timeout.timeout(Capybara.default_max_wait_time) do | |
loop until finished_all_angular_async_requests? | |
end | |
end | |
def finished_all_angular_async_requests? | |
page.evaluate_script('angular.element(document.body).injector().get(\'$http\').pendingRequests.length').zero? | |
end | |
end | |
World(WaitForAngularSync) # make helpers available to our steps in Cucumber |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment