Angular 角度异步检测更改
在没有试验台的情况下,如何“检测”角度测试中的变化 通过一个组件,我将实现以下功能:Angular 角度异步检测更改,angular,asynchronous,testing,Angular,Asynchronous,Testing,在没有试验台的情况下,如何“检测”角度测试中的变化 通过一个组件,我将实现以下功能: it('should work', async(() => { const fixture = TestBed.createComponent(TestComponent); // do some async call fixture.detectChanges(); // <=== This is what I want expect(something).toEqual(so
it('should work', async(() => {
const fixture = TestBed.createComponent(TestComponent);
// do some async call
fixture.detectChanges(); // <=== This is what I want
expect(something).toEqual(somethingElse);
});
如何将这些连接起来?如果我有两个阶段要检查(例如,异步工作前一个阶段,异步工作后一个阶段,但在某个初始阶段后全部检查)?使用
fakeAsync
和勾选功能模拟时间段
it('should work', fakeAsync(() => {
const fixture = TestBed.createComponent(TestComponent);
// do some async call
tick(10000);
expect(something).toEqual(somethingElse);
});
这是一个临时解决方案,在某些情况下,我依赖于我无法控制的东西来获取这些传入的数据。谢谢你。
it('should work', fakeAsync(() => {
const fixture = TestBed.createComponent(TestComponent);
// do some async call
tick(10000);
expect(something).toEqual(somethingElse);
});