gpt4 book ai didi

angularjs - 将 Angular 2.21 升级到 2.25 时,Jasmine httpBackend 相关测试中断

转载 作者:行者123 更新时间:2023-12-04 11:51:34 28 4
gpt4 key购买 nike

我在 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() 调用)失败了。幸运的是,我们可以指示它不执行摘要 - 注意 false范围:

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

关于angularjs - 将 Angular 2.21 升级到 2.25 时,Jasmine httpBackend 相关测试中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25885397/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com