0

如何访问控制器规范中的 json 对象?使用 jasmine getJson Fixtures 和 httpbackend 尝试了很多网络选项,但似乎没有任何效果。

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);

});
4

0 回答 0