-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
capybara-angular does not wait for route changes #17
Comments
Agree this would be useful. Though it should only work in ngRoute or ui-router is being used. This is what I do in my app currently: # spec/support/route_changes.rb
module RouteChange
def wait_for_route_changes
page.evaluate_script <<-JS
angular.element(document).ready(function() {
var app = angular.element(document.querySelector('[ng-app], [data-ng-app]'));
var injector = app.injector();
injector.invoke(function($rootScope) {
$rootScope.$on("$routeChangeStart", function() {
window.angularReady = false;
});
var ready = function() { window.angularReady = true };
$rootScope.$on("$routeChangeSuccess", ready);
$rootScope.$on("$routeChangeError", ready);
});
});
JS
end
end Then include it in spec_helper: config.include Capybara::Angular::DSL
config.include RouteChange, type: :feature And in my feature spec: scenario "search for a product" do
visit root_path
wait_for_route_changes
within :css, "form[name=SearchForm]" do
fill_in "keywords", with: "shirt"
click_on "Search"
end
expect(page.all('.product-listing .product').size).to eq(1)
end |
I agree with it as an option to opt-in for.
There might be a better way to check if the application is using ngRoute, and |
I am testing a login page, and after a successful login, I should be redirected to the dashboard page.
I am using the ng-routes module, not the angular-ui-router. My test for asserting this route change always fails.
my assertion looks like this:
expect(current_url).to eq("#{@app_host}/#/dashboard")
I see that the way capybara-angular checks to see if angular is ready is just by counting outstanding XHR requests.I think waiting for route changes should be a part of what this library covers.
The text was updated successfully, but these errors were encountered: