mardi 30 août 2016

How to resolve then() promise in Karma(w mocha)

I am trying to test the following component's controller lookup function:

lookup () {
    if (this.index == 1) {
        return this.$http.get('http://ift.tt/fyw30c').then(res => {
            this.index = res.data;
            return res;
        });
    }
}

To test it, this is what I am doing:

 controller.lookup();

It is only executing this line

if (this.find.index == 1) {
        return this.$http.get('http://ift.tt/fyw30c')

and not executing .then(..) promise

I also tried using scope.$digest(); and scope.$apply(); but it still not resolving then promise.

controller.lookup(function(response) {
   console.log(controller.index);
    expect(controller.index).is.equal(1);
    done();
  });

Aucun commentaire:

Enregistrer un commentaire