[英]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.