Unit testing AngularJS controller , Accessing Json in spec file

160 views Asked by At

How do i access a json object in the controller spec ? tried a lot of options of the net with jasmine getJson Fixtures and httpbackend but nothing seems to work.

beforeEach(inject(function ($injector,$controller, $rootScope, $q, _$timeout_,_$httpBackend){

$httpBackend = $injector.get('$httpBackend');
jasmine.getJSONFixtures().fixturesPath='base/client/json';

$httpBackend.whenGET('../api').respond(
    getJSONFixture('AuthenticatDI_Response.json')
);

scope = $rootScope.$new();
//declare the controller and inject our empty scope
    $controller('DashboardCtrl', {$scope: scope});
}));

afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
 });

it('should have some result', function() {
 console.log(scope);
 $httpBackend.flush();
 expect(scope.userProfile.length).toBe(1);

});
0

There are 0 answers