Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度异步检测更改_Angular_Asynchronous_Testing - Fatal编程技术网

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);
});