vendredi 23 octobre 2015

AngularJS, Mocha, Chai: testing service with promises

I've found several posts that shows this code as a way to do async unit testing:

The service:

angular.module('miservices', [])
.service('myAppServices', ['$http', 'httpcalls', function($http, httpcalls) {
    this.getAccountType = function(){
        return httpcalls.doGet('http://localhost:3010/...').then(function(data){
            return data;
        }, function(error){
            ...
        });
    };
    ...

The test:

describe('testing myAppServices', function(){

beforeEach(module('smsApp'));
it('should handle names correctly', inject(function(myAppServices){
  myAppServices.getAccountType()
  .then(function(data) {
      expect(data).equal({...});
});
...

We're using AngularJS, Mocha, Chai and we have Sinon installed.

The test never gets to the .then part, but why?

Thanks!

Aucun commentaire:

Enregistrer un commentaire