0

Component :

Global variable declaration

sub:any = []

ngonit()

{

this.sub =

this.router.params.subscribe(par

ams =>

{

this.taskId = params['taskId']

}

Spec.file:

what I tried sofar...

  1. I tried creating below params object

activateStub = {

params: {

subscribe() {

return of('taskId' : 1})

}

}

}

And added as use value in provider

{

provide : ActivateRoute,

useValue: activateStub

}

test case

it(test ngonit) => {

component.ngonit():

expect(component.ngOnIt).toBeTruthy();

}

Error am getting is:

component threw errors during cleanup,

this line is coming from ngdestroy function in component where the global variable this.sub is uses, where sub is not having any observable to un subscribe

ngdestroy() {

this.sub.unsubscribe();

}

Could you please help me on mocking the variable this.sub in other ways.

Thanks in advance.

Adithya
  • 183
  • 1
  • 2
  • 16

0 Answers0