简体   繁体   English

如何在Angular 2测试中对fixture.whenStable使用wait

[英]How to use await on fixture.whenStable in Angular 2 Tests

Though whenStable returns a promise, I'm not allowed to use await. 尽管whenStable返回了诺言,但我不允许使用await。

Below are my tsconfig 下面是我的tsconfig

"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
  "node_modules/@types"
],

I'm using "typescript": "^2.1.5" 我正在使用"typescript": "^2.1.5"

As stated in the error message: 'await' is only allowed within async function. 如错误消息中所述:仅在异步函数中允许使用“ await”。 When you want to use await , you have to mark the outer function with async keyword. 当您要使用await ,必须使用async关键字标记外部函数。

// example

const myAsyncFunction = async () => {
   // ... some code
   await fixture.whenStable();
   // ... some code
}

When you mark any function with async keyword it returns a promise. 当您使用async关键字标记任何函数时,它将返回一个promise。 Take a look at this question for better explanation of async/await. 看一下这个问题,以更好地解释异步/等待。

暂无
暂无

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

相关问题 Angular 中 async/await 和 async/fixture.whenStable 的区别 - Difference between async/await and async/fixture.whenStable in Angular 使用Angular夹具。当同步稳定 - Using Angular fixture.whenStable synchronously 如果不在异步测试执行区域内,fixture.whenStable() 实际上是否在我的角度测试中执行任何操作? - Does fixture.whenStable() actually do anything in my angular tests if not within an async test execution zone? 从 Angular 4 升级到 6 后,fixture.whenStable() 停止工作/调用 - fixture.whenStable() is stopped working/called after upgrading from Angular 4 to 6 角度4.3.0在执行异步函数后调用fixture.whenStable - angular 4.3.0 calling fixture.whenStable after executing an asynchronous function Angular Karma:从 Angular v8 升级到 v12 后,await fixture.whenStable 总是超时 - Angular Karma: await fixture.whenStable always times out after upgrade from Angular v8 to v12 测试我的组件时,夹具.whenStable()永远无法解析 - fixture.whenStable() never resolves when testing my component fixture.whenStable().then 中写入的所有预期条件都在填充,因为 SPEC 没有预期 - All expected conditions written in fixture.whenStable().then are populating as SPEC HAS NO EXPECTATIONS Angular2 whenStable()不能与observable一起使用? - Angular2 whenStable() not working with observable? angular的NGRX效果中如何使用async和await - How to use async and await in NGRX effect of angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM