- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 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
最佳答案
对于那些坚持使用旧的 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/
在阅读了$httpBackend的AngularJS文档后,我还是不太清楚$httpBackend.expect和$httpBackend.when之间的区别,因为两者都是函数模拟 http 请求。
$httpBackend.whenGET('/restpath/api/v1/books') .respond({// some data}); 我收到以下错误 Error: Unexpected r
经过太多时间后,我终其一生都无法让这个示例正常工作。我正在关注 Ben Lesh 的 excellent guides在 Angular 中模拟 $http 请求,但由于某种原因,服务请求未发送。 我
我在开发 Feed (RSS) 应用程序时正在使用 AngularJS 单元测试。 Feed 可以获取远程 rss 数据并对其进行解析并保存解析的项目。为了测试 rss 获取,我使用 $httpBac
我有包含单元测试的 AngularJS 应用程序。我在检查用户身份验证的应用程序的 .run 部分中又添加了一个 http 请求。现在大约 60% 的测试失败了,因为他们发现了“意外的 http 请求
我有 Angular (1.2.x) 单元测试,我正在使用 ngMock。我的项目有一个依赖于 sinon.fakeServer 的夹具系统。对于我的单元测试,我更愿意使用它而不是 $httpBack
在我看来,我有加载动画,该动画一直显示到我收到来自 API 的响应。 //Displayed before we've received API response Loading ... //Disp
我刚刚开始通过 Jasmine 在 AngularJS 中编写我的第一个单元测试。 不知何故,我仍然不明白为什么我应该模拟 $httpBackend。为了弄清楚我还不清楚的地方,我会写一个小例子: 想
我正在尝试将 url 与正则表达式匹配。但是下面的正则表达式不匹配。 $httpBackend.whenGET('/^rest\/find-reservations\?.*/)').respond(f
whenGET 不是函数,但是当我输出 proxy 时var 我清楚地看到函数在那里 { when: [Function], whenGET: [Function], whenPUT:
我遇到的情况是有很多模拟的 http 请求。在进行 Angular 上传时,我的情况发生了一些可疑的事情。它总是抛出 status:200 success 和 html 完整正文响应。 下面是我的 A
我正在尝试测试我的程序是否正确处理从 http 请求中收到的错误消息,但我不知道如何使用 $httpBackend 来模拟它。鉴于以下情况: $httpBackend.expectGET(path).
我正在使用 HttpBackend 来模拟我的 Angular 应用程序正在进行的某些调用的一些 Http 响应。 但是,当我运行测试时,我收到错误“意外请求:[object Object] 未定义”
我正在尝试围绕我的 Angular 项目构建一些 jasmine 单元测试。我遇到了一种情况,我不确定如何最好地解决。 我使用了一个响应拦截器,它能够在确定错误是 401 错误时重试请求。它将调用更新
我刚刚开始深入研究 AngularJS 的一些测试,但我不能说我完全理解它。我想在我的工厂中测试 REST API 方法,但我只是遇到错误。不知道我做错了什么。谁能帮帮我? 我的工厂: 'use st
我有这个 URL 可以匹配: $httpBackend.whenGET('/api/alerts/1121212156/0/4/0').repond(someObject) 问题是 112121215
我正在使用 Karma 对我的 AngularJS 应用程序进行单元测试,并使用 $HttpBackend 对后端进行 stub 。不知何故,flush() 方法似乎并没有解决我的所有请求,因为 Co
我正在开发一个 Angular 应用程序。我的应用程序运行时只有很少的 Controller 和服务。现在我想开始对服务和 Controller 进行单元测试。但是不知道我做错了什么,我什至无法为一项
我正在尝试为我正在使用 Angular JS 构建的应用程序模拟后端。 我有以下代码来模拟成功的登录请求: // Login $httpBackend.when('PUT','/v1/token/',
我有一个 $resource 用于处理实体的 crud http 请求。它包含在我的自定义服务中,目前不添加任何功能,所以不要介意它 - 它只是旧的普通 $resource: app.factory(
我是一名优秀的程序员,十分优秀!