繼angularJS $httpBackend官方指導我會做這個測試,但噶給我這個錯誤: Error: No pending request to flush ! at Function.$httpBackend.flush
測試
'use strict';
describe('profileCtrl', function() {
var scope, $httpBackend;
beforeEach(angular.mock.module('maap'));
beforeEach(angular.mock.inject(function($rootScope, $controller, _$httpBackend_){
$httpBackend = _$httpBackend_;
$httpBackend.when('GET', 'profile').respond([{id: 1, name: 'Bob'}]);
scope = $rootScope.$new();
$controller('profileCtrl', {$scope: scope});
}))
it('should fetch list of users', function(){
$httpBackend.flush();
expectGET(scope.current_user.length).toBe(1);
expect(scope.current_user[0].name).toBe('Bob');
});
});
對於這個簡單控制器:
'use strict';
angular.module('maap').controller('profileCtrl', function($scope, UserService) {
$scope.current_user = UserService.details(0);
});
它是警告還是錯誤? – madhured
@madhured這是一個錯誤 – Tres