I recently developed a mock Angular service specifically for testing a controller. However, whenever I run my tests, an error pops up saying:
Unexpected request: GET ./fixtures/stats.json
.
This is how the code looks like in mock.players.service.js:
'use strict';
angular.module('mockPlayersService', [])
.factory('playersService', ['$http', '$q',
function($http, $q) {
var playersService = {};
playersService.stats = $http.get('./fixtures/stats.json');
playersService.getStats = function() {
var defer = $q.defer();
defer.resolve(this.stats);
return angular.extend({$promise: defer.promise}, this.stats);
};
return playersService;
}]);
I am thinking maybe there's something missing in my controller spec to handle this GET
request, or should I include the 'fixtures' path in my 'karma.config.js' 'files' array?
UPDATE: As per my current setup (which is functional), it looks like this:
playersService.stats = {
'firstName': 'John',
'middleName': 'James',
'lastName': 'Doe',
'city': 'Cleveland',
'state': 'OH',
};
playersService.getStats = function() {
var defer = $q.defer();
defer.resolve(this.stats);
return angular.extend({$promise: defer.promise}, this.stats);
};
My goal now is to relocate that existing playersService.stats
object into a JSON fixture.