Injecting Router during unit tests (rc.5, Router 3.0.0-rc.1)

I am trying to unit test a component using a router, my code is in typescript. There are many recipes for entering Router into the test specification, but none of them work for me, and some of them are not suitable for use in the current version. I tried this:

beforeEach(() => { addProviders([ MyComponent, provideRouter([]), provide(APP_BASE_HREF, { useValue: '/' }), provide(ActivatedRoute, { useValue: {} }) ]); }); 

and got an error message

 Error: Bootstrap at least one component before injecting Router. 

When I generally try to mock the Router:

 class MockRouter { public navigate() {} } beforeEach(() => { addProviders([ MyComponent, provide(Router, { useClass: MockRouter }) ]); }); 

the test suite stops completely with an error message

 TypeError: Attempting to configurable attribute of unconfigurable property. 

In router_testing_module.d.ts they offer the following:

 beforeEach(() => { configureModule({ modules: [RouterTestingModule], providers: [provideRoutes( [{path: '', component: BlankCmp}, {path: 'simple', component: SimpleCmp}])] }); }); 

But the configureModule function does not seem to exist (yet? More?).

What can I do in this situation?

+5
source share

All Articles