angularjs – Jasmine控制器测试:$timeout.flush()导致’意外的
发布时间:2020-12-17 17:13:44 所属栏目:安全 来源:网络整理
导读:我有以下测试: 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(productGrou
我有以下测试:
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中的数据时遇到了一些问题. 现在,没有标记的行,测试运行查找,除了未获得预期结果. 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中,但它没有帮助: $templateCache.put('views/main.html',$templateCache.get('app/views/views/main.html')); 任何援助将不胜感激. 解决方法
解决方案我能够想到的是:
$httpBackend.when('GET','views/main.html').respond(''); 在beforeEach函数中 没有别的东西似乎不起作用. 虽然它是用于单元测试目的的有效解决方案,但它永远不会用于E2E测试. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |