jeudi 2 février 2017

Why does my route action with async operation inside a service not work properly when acceptance testing it?

I am on "ember-cli": "2.10.0", and the following acceptance test fails when introducing an async fetch call using a service. it runs when using the async fetch() directly in the action. Is this a bug or am I just missing same basic concept here?

//acceptance/login-test.js
test('dosomething with redirect after async action', function(assert) {
  // fire the login action in the Login contoller
  click('[name="buttonLogin"]');  
  andThen(() => {
    assert.equal('/protected', currentURL(), 'redirect went well')
  });
});

I got the following login controller:

// controllers/login.js
session: Ember.inject.service(),
actions: {
  // acceptance tests runs fine
  login() {
    fetch('http://ift.tt/2kY4tCT')
    .then((response) => {
      this.transitionToRoute('protected');
    });
  },
  // the test always fails ( expected: "/protected", actual: "/login" )
  // eventhough its basically the same code, isntit?
  login() {
    this.get('session').authenticate().then(()=>{
      this.transitionToRoute('protected');
    });
  }
}

-

//services/session.js
..
authenticate() {
    return fetch('http://ift.tt/2kY4tCT');
}




Aucun commentaire:

Enregistrer un commentaire