Jasmine Controller测试:$ timeout.flush()导致'意外的GET请求'错误 [英] Jasmine Controller test: $timeout.flush() causes an 'Unexpected GET request' error
问题描述
我有以下测试:
it('should load productGroups into the scope', function(){
scope._section = 'modifiers';
scope.userData = {method: 'manual'};
scope.$digest();
timeout.flush();//causes the error
expect(scope.productGroups).toEqual(productGroupService.getProductGroups());
});
现在,由于某些问题,我尝试测试的操作发生在超时0内我同步了存储在cookie中的数据。
Now, the action that I am trying to test occurs within a timeout of 0, because of some issues I had with syncing the data stored in the cookies.
现在,没有标记的行,测试运行find,除了没有获得预期的结果。
使用标记的行,我收到以下错误:
Now, without the marked line, the test runs find, except the expected result is not obtained. With the marked line, I get the following error:
Error: Unexpected request: GET views/main.html
No more request expected
at $httpBackend (/home/oleg/dev/vita-webapp-new/bower_components/angular-mocks/angular-mocks.js:1178:9)
at sendReq (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:8180:9)
at $http.serverRequest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:7921:16)
at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
at wrappedCallback (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11319:81)
at /home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:11405:26
at Scope.$eval (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12412:28)
at Scope.$digest (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12224:31)
at Scope.$apply (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:12516:24)
at Object.fn (/home/oleg/dev/vita-webapp-new/bower_components/angular/angular.js:14023:36)
Process finished with exit code 0
main.html,显然是这个控制器的视图,尝试使用以下代码将其放在templateCache中,但它确实没有帮助:
main.html, is obviously the view of this controller, tried placing it in templateCache with the following code, but it did not help:
$templateCache.put('views/main.html', $templateCache.get('app/views/views/main.html'));
非常感谢任何帮助。
推荐答案
我能够提出的解决方案是:
Solution I've been able to come up with is:
$httpBackend.when('GET', 'views/main.html').respond('');
beforeEach
函数中的
in the beforeEach
function
其他任何东西似乎都不起作用。
Nothing else doesn't seem to work.
虽然它是用于单元测试目的的可行解决方案,但它永远不会起作用进行E2E测试。
While it's a working solution for unit-testing purposes, it would never work for an E2E test.
这篇关于Jasmine Controller测试:$ timeout.flush()导致'意外的GET请求'错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!