My goal is to populate the html with data using the pre-set response from the AngularJS mocking service (jasmine). In case the mock response fails, there is a fallback option where "http" would be displayed instead of "mock". However, the response always shows as "http", indicating that the mock service is not functioning properly. I would greatly appreciate any insights or ideas on how to resolve this issue.
Sample Jasmine javascript file:
describe("DController", function() {
var httpBackend,scope;
beforeEach(module('MyApp'));
beforeEach(inject(function($rootScope,$httpBackend,$http,$controller) {
scope = $rootScope.$new();
httpBackend = $httpBackend;
DController = $controller('DController', {
$scope: scope
});
httpBackend.expectGET('data.json').respond({
"name": "mock"
});
})); })
Code snippet from controller.js file:
.controller('DController',function($scope,$http) {'use strict';
$scope.loadJson = function() {
var getDataJson = $http.get('data.json');
getDataJson.success(function(data, status, headers, config) {
$scope.data = data;
});
}})
The content of data.json simply states:
{ "name": "http" }