Testing Angular component with unsubscribe Error during cleanup of component

后端 未结 10 1694
梦毁少年i
梦毁少年i 2021-01-30 10:37

I\'m testing a component which subscribe router params. Every test pass and everything works fine. But if I look in the console, I can see an error:

Error

10条回答
  •  终归单人心
    2021-01-30 11:20

    I'm in a similar situation where I want to test a function in my component outside the context of the component itself.

    This is what worked for me:

    afterEach(() => {
      spyOn(component, 'ngOnDestroy').and.callFake(() => { });
      fixture.destroy();
    });
    

提交回复
热议问题