将Angular 2.21升级到2.25时,与Jasmine httpBackend相关的测试被破坏

Ask*_*mov 7 jasmine angularjs karma-jasmine

我在Jasmine和Karma中有很多依赖于$ httpBackend HTTP模拟检查的测试.当我今天升级Angular时,他们停止了工作.

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

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

在最后一行,这是完全正常的,我收到:

    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
Run Code Online (Sandbox Code Playgroud)

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

afterEach(function () {
    httpBackend.verifyNoOutstandingExpectation();
    httpBackend.verifyNoOutstandingRequest();
});
Run Code Online (Sandbox Code Playgroud)

现在开始生成以下错误:

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
Run Code Online (Sandbox Code Playgroud)

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

Ant*_*ton 7

对于那些被卡住的老角谁,在这一点上由于某种原因不能升级,这里是一个伟大的职位解释这是怎么回事,如何解决这个问题.

总结一下 -

问题发生是因为两者$httpBackend.flush()$httpBackend.verifyNoOutstandingExpectation()错误地尝试做消化.显然,内部(来自verifyNoOutstandingExpectation()呼叫)失败.幸运的是,我们可以指示它不要执行摘要 - 请注意false参数:

afterEach(function() {
    $httpBackend.verifyNoOutstandingExpectation(false); // <-- here
    $httpBackend.verifyNoOutstandingRequest();
});
Run Code Online (Sandbox Code Playgroud)