2016-08-03 2 views
3

오류 여기오류 : h 제되지 않은 요청 카르마

Error: Unflushed requests: 1 in /Users/..etc/angular-mocks.js 

을하는 HTTP 호출을 조롱하려고하지만 점점 내 관련 코드

describe('Tests for Group Controller', function() { 
    var $httpBackend; 
    beforeEach(function() { 
    module('App'); 
    return inject(function($injector) { 
     var $controller; 
     $window = $injector.get('$window'); 
     $window.ENV = 'http://here.com' 
     this.rootScope = $injector.get('$rootScope'); 
     this.state = {}; 
     this.stateParams = {}; 
     this.UserService = $injector.get('UserService'); 
     this.ProjectService = $q = $injector.get('ProjectService'); 
     this.ModalService = {}; 
     $httpBackend = $injector.get('$httpBackend'); 
     this.GroupService = {}; 
     $q = $injector.get('$q'); 
     this.q = $q; 
     $controller = $injector.get('$controller'); 
     this.scope = this.rootScope.$new(); 
     this.controller = $controller('GroupController', { 
     '$scope': this.scope, 
     '$state': this.state, 
     '$stateParams': this.stateParams, 
     "UserService": this.UserService, 
     'ProjectService': this.ProjectService, 
     'ModalService': this.ModalService, 
     'GroupService': this.GroupService, 
     '$q': this.q 
     }); 
     // this.scope.$digest(); 
     $httpBackend.when('GET', 'http://here.com/api/user/2/Group/list?offset=0&max=10&sortField=name&ascending=true').respond({data: 'success'}); 
    }); 


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

    it('should have controller defined', function() { 
    expect(this.controller).toBeDefined() 
    }); 

    it('should initGroups', function() { 
    $httpBackend.expectGET('http://here.com/api/user/2/Group/list?offset=0&max=10&sortField=name&ascending=true'); 
    $httpBackend.flush(); 
    }) 
}); 

나는 expectget 후 세척을하고 있어요하지만 여전히 말한다이다 나는 unflushed 요청을했습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

0

각 테스트 전에 GET 요청을 만들지 만 'Should initGroups'테스트에서만 플러시하십시오.