测试代码中有几个问题:
- 所述控制器被创建 之前 的
httpMock
被构造成与响应pig
。该expectGet
调用应在实例化控制器之前发生。 - 在
httpMock
需要刷新请求 - 的
httMock.when
,只要你有没有必要expectGet
工作示例:http :
//plnkr.co/edit/lUkDMrsy1KJNai3ndtng?p=preview
describe('cDashboard', function(){ var scope, controllerService, httpMock; beforeEach(inject(function ($rootScope, $controller, $httpBackend) { scope = $rootScope.$new(); controllerService = $controller; httpMock = $httpBackend; })); it("should get 'pig' from '/data'", function () { httpMock.expectGET("/data").respond("pig"); ctrl = controllerService('cDashboard', {$scope: scope}); httpMock.flush(); expect(scope.data).toBe("pig"); });});
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)