0

I have code that i subscribe to activatedRoute.url and inside the subscription im accsessing the sanpshot data. I created mock for the activatedRoute but my test keeps failing .

This is the test code

This is the code i want to test

This is the test

I have tried to to change the code without the subscription and it worked. But when i try to do it inside the subscripion the test fails.

1 Answers1

0

I think you should wrap your test inside a fakeAsync with a tick() call to wait for the code inside the subscription.

it('should wait', fakeAsync(() => {
  ...
  component.ngAfterViewInit();
  tick();
  expect(something);
}));
Alejandro Barone
  • 1,743
  • 2
  • 13
  • 24