Testing Angular component with unsubscribe Error during cleanup of component

后端 未结 10 1656
梦毁少年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条回答
  •  闹比i
    闹比i (楼主)
    2021-01-30 11:11

    So my situation was similar, but not exactly the same: I'm just putting this here in case someone else finds it helpful. When unit testing with Jamine/Karma I was getting

     'ERROR: 'Error during cleanup of component','
    

    It turns out that was because I wasn't properly handling my observables, and they didn't have an error function on them. So the fix was adding an error function:

    this.entityService.subscribe((items) => {
          ///Do work
    },
      error => {
        this.errorEventBus.throw(error);
      });
    

提交回复
热议问题