在Angular / Karma单元测试中未运行fakeAsync测试

时间:2020-06-19 15:41:02

标签: angular unit-testing asynchronous testing karma-jasmine

我正在Angular 8项目中工作。

我正在为setTimeout为1000ms的函数编写测试。 我对此进行了研究使用fakeAsync,但遇到了一些问题。 这是我的测试:

fdescribe("redirectToErrorPage", () => {
    it("should set confirmationNavigation to false after timeout"),
      fakeAsync(() => {
        component.confirmNavigation = true;
        component.redirectToErrorPage();  //this func has a setTimeout
        expect(component.confirmNavigation).toBeTruthy(); //before tick, will still be true
        tick(1001);
        expect(component.confirmNavigation).toBeFalsy();
      });
  });

我只关注那个测试,当我运行它时,它表明没有完成测试。

0 tests completed

enter image description here

从业力输出中可以看到我有“ 1个待定规格”。

如何解决此待处理的规范? 如何使我的fakeAsync测试与输出一起运行?上面的测试应该通过了,但是即使我将错误更改为真实,输出也不会更改。我也可以取消测试的重点,然后与其他人一起运行并获得相同的结果。

任何帮助将不胜感激。

0 个答案:

没有答案