2016-08-03 27 views
3

Der Versuch, einen HTTP-Aufruf zu verspotten, aber immer den FehlerFehler: unflushed Anfragen Karma

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

hier ist mein entsprechenden Code

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

ich die Spülung nach dem expectget tun, aber es sagt noch Ich habe eine unbedarfte Bitte. Was mache ich falsch?

Antwort

0

Sie erstellen GET-Anforderung vor jedem Test, aber es nur in "Should initGroups" test.