How to correctly use SharedModules with Router while testing angular 2 application?

前端 未结 2 1270
小蘑菇
小蘑菇 2021-01-12 23:15

I\'m trying to unit test a (angular 2) component with routerLink and routerLinkActive but all test cases fail with following error message. (

2条回答
  •  忘掉有多难
    2021-01-13 00:08

    Angular has no way of knowing that you want it to use the activatedRoute variable that you created yourself(as per comment) so it will create default one and use that in DI. Instead of the current setup for the ActivatedRoute dependency use { provide: ActivatedRoute, useValue: mockInstance} where mockInstance is a mock of ActivatedRoute, you can create that with jasmine.createSpyObj

提交回复
热议问题