简体   繁体   English

Angular Karma:从 Angular v8 升级到 v12 后,await fixture.whenStable 总是超时

[英]Angular Karma: await fixture.whenStable always times out after upgrade from Angular v8 to v12

I have some unit tests for a component that uses reactive forms.我对使用反应式形式的组件进行了一些单元测试。

In the tests, I will patch values on the form, and then the unit test will test what I expect from various form valueChanges subscriptions.在测试中,我将修补表单上的值,然后单元测试将测试我对各种表单valueChanges订阅的期望。

So that the test waits for the valueChanges to execute, I always used the following after the patch :为了让测试等待valueChanges执行,我总是在patch后使用以下内容:

fixture.detectChanges();
await fixture.whenStable();

and this always worked fine.这总是很好用。

After my upgrade (went from v8 to v12), all tests time out when I have the await fixture.whenStable() .升级后(从 v8 升级到 v12),当我有await fixture.whenStable()时,所有测试都会超时。

Ie I get:即我得到:

    Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
    error properties: Object({ originalStack: 'Error: Timeout - Async function did not complete within 5000ms (set by jasmine.DEFAULT_TIMEOUT_INTERVAL)
            at new ZoneAwareError (http://localhost:9877/_karma_webpack_/webpack:/node_modules/zone.js/fesm2015/zone-error.js:92:33)

Of course, if I remove the await fixture.whenStable();当然,如果我删除await fixture.whenStable(); the test no longer works, as when I try and access the properties set is the form valueChanges they are not set.测试不再有效,因为当我尝试访问属性集时,它们没有设置表单valueChanges

Why would the await fixture.whenStable() now seem to hang?为什么await fixture.whenStable()现在似乎挂起?

Coming back to this today, I think I found the problem (in my case).今天回到这个问题,我想我发现了问题(就我而言)。

I had a setTimeout in the components ngAfterViewInit() which was not being cleared.我在组件ngAfterViewInit()中有一个未清除的setTimeout Infact having the setTimeout at all was a bug, it was only need to go off once, so should have been a setInterval .事实上,有 setTimeout 是一个错误,它只需要关闭一次,所以应该是一个setInterval I did have some problems with the ngAfterViewInit so I already had我确实对ngAfterViewInit有一些问题,所以我已经有了

spyOn(component, 'ngAfterViewInit').and.callFake(() => { });

as the code in the timer was not that important (just turing animations on/off), so still not 100% sure why a change in the real ngAfterViewInit made a difference... and yet it did, my await fixture.whenStable();由于计时器中的代码不是那么重要(只是打开/关闭动画),所以仍然不能 100% 确定为什么真正的ngAfterViewInit的更改会有所不同......但它确实如此,我的await fixture.whenStable(); no longer hangs, and the test now waits for the forms valueChanges .不再挂起,测试现在等待表单valueChanges

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Angular 4 升级到 6 后,fixture.whenStable() 停止工作/调用 - fixture.whenStable() is stopped working/called after upgrading from Angular 4 to 6 Angular 中 async/await 和 async/fixture.whenStable 的区别 - Difference between async/await and async/fixture.whenStable in Angular 如何在Angular 2测试中对fixture.whenStable使用wait - How to use await on fixture.whenStable in Angular 2 Tests 角度4.3.0在执行异步函数后调用fixture.whenStable - angular 4.3.0 calling fixture.whenStable after executing an asynchronous function 使用Angular夹具。当同步稳定 - Using Angular fixture.whenStable synchronously Angular:Karma 给出错误错误:NullInjectorError:没有提供 ElementRef! 从 v7 升级到 v8 后 - Angular: Karma giving error Error: NullInjectorError: No provider for ElementRef! after upgrade from v7 to v8 Angular Angular 从 v7 升级到 v8 后出现 Karma 错误 - Angular Karma error after upgrading Angular from v7 to v8 Angular 从 v12 迁移到 v14 - Angular migration from v12 to v14 如果不在异步测试执行区域内,fixture.whenStable() 实际上是否在我的角度测试中执行任何操作? - Does fixture.whenStable() actually do anything in my angular tests if not within an async test execution zone? 从 Angular v7 升级到 v8 后,显示“my-custom-element”的 Vscode 不是已知元素 - Vscode displaying "my-custom-element" is not a known element after upgrade from Angular v7 to v8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM