3
試圖嘲笑HTTP調用,但得到的錯誤錯誤:未刷新請求噶
Error: Unflushed requests: 1 in /Users/..etc/angular-mocks.js
這裏是我的相關代碼
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之後,但它仍然說我有一個不需要的請求。我究竟做錯了什麼?