小编Jus*_*lan的帖子

TestBed.get 和 new Service(...dependencies) 有什么区别

角度导向演示通过调用新服务(),并且直接提供所述依赖于构造的测试,一个的两种不同的方式,并通过调用TestBed.get(服务)使用依赖注入的第二个。

这两个对我来说在功能上似乎相同,除非我连续调用 TestBed.get() 时它不会在第一次调用后调用构造函数。

角文件还提到,TestBed.get()已过时(尽管仍然指南参考吧!),我应该使用类型InjectionToken代替,但我看不出这些类的任何可取代TestBed.get() .

testing jasmine typescript angular

8
推荐指数
3
解决办法
1万
查看次数

角度测试中tick()和flush()有什么区别?

在角度文档中,我看到了这两个功能,tick()flush()。两者似乎都做类似的事情。从角度文档中,它会打勾:

为fakeAsync区域中的计时器模拟时间的异步传递。

和冲洗:

通过清空宏任务队列直到其为空来模拟fakeAsync区域中计时器的异步时间流逝。返回的值是本应经过的毫秒数。

谁能向我解释差异?

编辑(在评论中回答):

此外,在角度文档 tick()中不带参数,并且该行的注释甚至使用了“ flush”一词。

it('should display error when TwainService fails', fakeAsync(() => {
  // tell spy to return an error observable
  getQuoteSpy.and.returnValue(
    throwError('TwainService test failure'));

  fixture.detectChanges(); // onInit()
  // sync spy errors immediately after init

  tick(); // flush the component's setTimeout()

  fixture.detectChanges(); // update errorMessage within setTimeout()

  expect(errorMessage()).toMatch(/test failure/, 'should display error');
  expect(quoteEl.textContent).toBe('...', 'should show placeholder');
}));
Run Code Online (Sandbox Code Playgroud)

testing jasmine typescript ionic-framework angular

6
推荐指数
1
解决办法
994
查看次数

标签 统计

angular ×2

jasmine ×2

testing ×2

typescript ×2

ionic-framework ×1