I'm currently troubleshooting a simple service and encountering the error mentioned above. After extensive research, I believe there is a null item in my code that I cannot locate. Any insights or suggestions would be greatly appreciated. Thank you!
Config.js
'use strict';
angular.module('App').service('configService', function(
$rootScope, $http) {
var configObj = null;
return {
getConfig: function() {
if (configObj != null) {
console.log("returning cached config");
return configObj;
}
else {
$http.get('conf.json').then(function(res) {
$http.get(res.confLocation).then(function(
locationResponse) {
configObj = locationResponse;
$rootScope.configObj = configObj;
console.log($rootScope.configObj);
return configObj;
});
});
}
}
};
});
ConfigTest.js
'use strict';
describe('Service: configService', function() {
// load the controller's module
beforeEach(module('App'));
var configService, $httpBackend, results;
var tstConfig = {
"confLocation": "local-dev-conf.json"
};
var tstConfigObj = {
"AWS": {
"region": "us-east-1",
"endpoint": "http://localhost:8133"
}
};
// Initialize the controller and a mock scope
beforeEach(inject(function(_configService_, _$httpBackend_) {
inject(function($rootScope) {
$rootScope.USERNAME = 'TESTER';
$rootScope.configObj = tstConfigObj;
});
configService = configService;
$httpBackend = _$httpBackend_;
// backend definition common for all tests
$httpBackend.expectGET('conf.json').respond(tstConfig);
$httpBackend.expectGET('local-dev-conf.json').respond(tstConfigObj);
}));
it('it should do something', inject(function() {
results = configService.getConfig().then(function() { //ERROR HERE
// What should I be expecting to check if it's parsing the file?
// expect(configFile).toEqual("Object{AWS: Object{region: 'us-east-1', endpoint: 'http://localhost:8133'}}")
console.log(results);
});
$httpBackend.flush();
}));