加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 将Angular 2.21升级到2.25时,与Jasmine httpBacken

发布时间:2020-12-17 08:48:22 所属栏目:安全 来源:网络整理
导读:我在Jasmine和Karma中有很多依赖于$httpBackend HTTP模拟检查的测试.当我今天升级Angular时,他们停止了工作. 假设我的Jasmine测试中有这样的东西: // Arrange httpBackend.expect('POST','https://localhost:44300/api/projects/1/samples').respond(fakedD
我在Jasmine和Karma中有很多依赖于$httpBackend HTTP模拟检查的测试.当我今天升级Angular时,他们停止了工作.

假设我的Jasmine测试中有这样的东西:

// Arrange
    httpBackend.expect('POST','https://localhost:44300/api/projects/1/samples').respond(fakedDto);
    // Act
    scope.updateSamples();
    httpBackend.flush();

在最后一行,这是完全可以的,我收到:

TypeError: $browser.$$checkUrlChange is not a function in C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js (line 12502)
$RootScopeProvider/this.$get</Scope.prototype.$digest@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:12502:9
createHttpBackendMock/$httpBackend.flush@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular-mocks/angular-mocks.js:1481:5
@C:/SVN/samplemgmt/src/ClientApp/tests/integration/sample/samplecreationController_integration.test.js:341:9

此外,我有通常的配置来结束测试:

afterEach(function () {
    httpBackend.verifyNoOutstandingExpectation();
    httpBackend.verifyNoOutstandingRequest();
});

现在开始生成以下错误:

Error: [$rootScope:inprog] $digest already in progress
http://errors.angularjs.org/1.2.25/$rootScope/inprog?p0=%24digest in C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js (line 78)
minErr/<@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:78:5
beginPhase@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:13009:9
$RootScopeProvider/this.$get</Scope.prototype.$digest@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular/angular.js:12500:9
createHttpBackendMock/$httpBackend.verifyNoOutstandingExpectation@C:/SVN/samplemgmt/src/ClientApp/client/bower_components/angular-mocks/angular-mocks.js:1514:5
@C:/SVN/samplemgmt/src/ClientApp/tests/integration/sample/samplecreationController_integration.test.js:137:9

我很欣赏一些如何让事情再次发挥作用的建议.最近是否对httpBackend测试做了任何更改?

对于那些坚持使用旧版Angular并且由于某种原因无法在此时升级的人来说,here是一个很好的帖子,它解释了正在发生的事情以及如何解决问题.

总结一下 –

出现此问题是因为$httpBackend.flush()和$httpBackend.verifyNoOutstandingExpectation()错误地尝试进行摘要.显然,内部的(来自verifyNoOutstandingExpectation()调用)失败.幸运的是,我们可以指示它不要执行摘要 – 请注意错误的参数:

afterEach(function() {
    $httpBackend.verifyNoOutstandingExpectation(false); // <-- here
    $httpBackend.verifyNoOutstandingRequest();
});

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读