Reputation: 1343
I have service A which calls another services B and in turn B which has $http injected call the API web-service.
Now when i tried to stub service B using Mocha Sinon I am getting the following error
Unexpected request: GET app/contract/forecast/il8n/en.json No more request expected
Note I am not using httpBackend anywhere in my code.
Code is as follow
var somePromise = B.getData(url,data);
somepromise.then(success, failed);
Test Code is
it('Testing A.loadCustomerInformation', function() {
var deferred = $q.defer();
var promise = deferred.promise;
sinon.stub(B,'getData').returns(promise);
deferred.resolve({data : customerInformation});
A.loadCustomerInformation(vm);
rootScope.$apply();
assert(B.getData.called);
assert(A.someotherMtd1.called);
assert(A.someotherMtd2.called);
});
Basically i want to stub service B function 'getData' and return mock response and check the vm(view model) object populated correctly against mock input.
I have following configuration
Gulp, Karma, phantom js, Mocha, Sinon etc..
Help is appreciated!
Upvotes: 0
Views: 380
Reputation: 1343
As i commented above, by following Unit Testing with Translate which i got from @Chasmo comments things set up nicely.. Following is the code i added
beforeEach(module('app', function ($provide, $translateProvider) {
$provide.factory('testLoader', function ($q) {
return function () {
var deferred = $q.defer();
deferred.resolve({});
return deferred.promise;
};
});
$translateProvider.useLoader('testLoader');
}));
Upvotes: 0