Unit testing in angular2, dependency injection

前端 未结 1 1996
说谎
说谎 2021-01-11 17:54

Starting out with angular 2 after spending time with angular 1. Not having unit tested this much as it\'s more of a side project thing, I\'m trying at least start out OK...

相关标签:
1条回答
  • 2021-01-11 18:36

    For testing, you should use the RouterTestingModule instead of the RouterModule. If you want to add routes you can use withRoutes

    imports: [
      RouterTestingModule.withRoutes(Routes) // same any normal route config
    ]
    

    See Also

    • Angular 2 unit testing components with routerLink
    • Second half of this post for an idea of mock the ActivatedRoute. Sometimes you don't want the whole routing facility when unit testing. You can just mock the route.
    0 讨论(0)
提交回复
热议问题