https://www.digitalocean.com/community/tutorials/angular-testing-async-fakeasync
The async utility tells Angular to run the code in a dedicated test zone that intercepts promises.
async可以让Angular在一个专属的test zone里执行代码,该zone可以截获promises.
whenStable: allows us to wait until all promises have been resolved to run our expectations.
当所有的promises都resolved之后,whenStable触发,能够进行expectation的evaluation了。
看个例子:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `
set title
`
})
export class AppComponent {
title: string;
setTitle() {
new Promise(resolve => {
resolve('One crazy app!');
}).then((val: string) => {
this.title = val;
});
}
}