Skip to content
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

Not waiting for $http #26

Open
nicooga opened this issue Feb 22, 2016 · 1 comment
Open

Not waiting for $http #26

nicooga opened this issue Feb 22, 2016 · 1 comment

Comments

@nicooga
Copy link

nicooga commented Feb 22, 2016

I'm using ui.router and angularjs-rails-resource.

The page I'm visiting has a directive that performs a query to the local API to get some models that populate a select for a form:

CarBrand.query().then(function(carBrands) {
  vm.carBrands = carBrands; // this never gets executed, the model is empty
});

I've opened the page with save_and_open_page to check the rendering state of the app, and the route is resolved (even without using the waiter mentioned in this other issue) and the form is rendered, but the select options are not populated.

I've run out of clues. I checked if there are pending requests as suggested here but the answer is no, there are no pending requests.

However, when I quit, in the last second the requests appear en in the network tab of firefox, as if something was holding them.

Test:

require "rails_helper"

describe "CarListing creation", type: :feature do
  let!(:car_version) { FactoryGirl.create :car_version }

  it "creates a CarListing", js: true do
    visit "/#/avisos/nuevo"

    wait_until_angular_ready
    wait_for_route_changes

    save_and_open_page

    select_by_ng_model "cL_EC.carListing.car.brand", car_version.brand.name
    select_by_ng_model "cL_EC.carListing.car.model", car_version.model.name
    select_by_ng_model "cL_EC.carListing.car.versionId", car_version.id
    fill_in_by_ng_model "cL_EC.carListing.car.year", 1996
  end

  def fill_in_by_ng_model(ng_model, value)
    find_by_ng_model(ng_model).set value
  end

  def select_by_ng_model(ng_model, value)
    find_by_ng_model(ng_model).
    find(:css, "option[value='#{value}']").
    select_option
  end

  def find_by_ng_model(ng_model)
    find(:css, "[ng-model='#{ng_model}']")
  end
end

I tried https://github.com/kikonen/capybara-ng with the same results. AFAIK, this library angularjs-rails-resource is just a wrapper around $http calls.

Any help is aprettiated!

@mebibou
Copy link

mebibou commented Apr 19, 2016

Have you tried putting the query in the controller of the page instead of your directive? is your directive even going through the linking or not at all? sounds to me like your directive is compiled later than when you request it. I personally have a routeProvider and some directives doing some loading and it works fine without waiting for angular at all, even before I used this library, so prob the problem lies somewhere else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants