Skip to content

Instantly share code, notes, and snippets.

@KBalderson
Created February 10, 2016 15:22
Show Gist options
  • Save KBalderson/06d26af1f868e4bc2911 to your computer and use it in GitHub Desktop.
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.
# 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