【发布时间】:2014-03-14 12:32:28
【问题描述】:
我有一个 Jasmine 测试,编码如下:
it ("should send correct message to server to get data, and correctly set up scope when receiving it", function(){
$httpBackend.when('GET', 'https://localhost:44300/api/projectconfiguration/12').respond(fakedDtoBase);
$routeParams.projectId=fakeId; // user asks for editing project
scope.$apply(function(){
var controller=controllerToTest(); // so controller gets data when it is created
});
expect(scope.projectData).toEqual(fakedDtoBase);
});
它有点工作,但我得到了错误:
Error: Unexpected request: GET views/core/main/main.html
No more request expected
at $httpBackend (C:/SVN/src/ClientApp/client/bower_components/angular-mocks/angular-mocks.js:1207:9)
at sendReq (C:/SVN/src/ClientApp/client/bower_components/angular/angular.js:7800:9)
at $http.serverRequest (C:/SVN/src/ClientApp/client/bower_components/angular/angular.js:7534:16)
(more stack trace)....
我确实意识到我可以模拟其他所有呼叫。但是假设我不在乎我的测试还想加载什么,因为它可能会调用其他一些东西。 我如何确保所有其他请求都“默默地发生”,也许为其他所有请求提供一个虚拟响应?
【问题讨论】:
标签: angularjs jasmine karma-runner