mercredi 27 avril 2016

Mocking the Service in Controller according to responce type

I have a controller as below which has dependency to customerService which will return search result based on listParam from server:

  self.result = [];
  self.listParam= {};

  self.search= function () {
            self.result.length = 0;
            self.findingPromise = customerService.find(self.listParam);
            self.findingPromise
                .then(function (response) {
                    self.result = response.data.Result;
                }, function (response) {
                    var r = response;
                    ngNotify.set('Some problems occurred!',
                        {
                            type: 'error',
                            position: 'top',
                            sticky: true
                        });
                });
        };

I want to use Jasmine for Unit Test. I've read Unit Testing for AngularJS article. But I don't understand how I should use mocking in this case (search). As you see, I may have resolved response or not based on service backend .

Aucun commentaire:

Enregistrer un commentaire