angularjs - Angular 2 testing with Router - Cannot resolve all parameters for 'Router' -


i'm trying test component injects router in constructor (typescript):

constructor(     private _router: router,     private dispatcher: observer<action>,     fb: formbuilder ) { ... } 

and have following test(s):

import { it, inject, injectasync, beforeeachproviders, testcomponentbuilder } "angular2/testing";  import {provide} "angular2/core"; import {formbuilder} 'angular2/common'; import {subject} 'rxjs/subject'; import {router, routeparams} 'angular2/router'; // other imports ...  describe("someinfoedit form", () => {      const actions = new subject<action>(null);      // provide our implementations or mocks dependency injector     beforeeachproviders(() => {          return [             router,             formbuilder,             provide(dispatcher, { usevalue: actions }),             someinfoedit         ];     });      it('should have default data', inject([someinfoedit], (component) => {         expect(component.galtitle.value).toequal("");         expect(component.friendlyurl.value).toequal("");         expect(component.isvisible.value).tobe(false);     })); ... 

when test runs error:

cannot resolve parameters 'router'(?, ?, ?). make sure parameters decorated inject or have valid type annotations , 'router' decorated injectable.

please that. love read explanation of what's going on (i read articles on di, so).

i should add code works, no problems. test doesn't.

ok, angular team got working:

import { spylocation } 'angular2/src/mock/location_mock'; import {rootrouter} 'angular2/src/router/router'; import {router, routeroutlet, routerlink, routeparams, routedata, location, router_primary_component} 'angular2/router'; import {   routeconfig,   route,   auxroute,   asyncroute,   redirect } 'angular2/src/router/route_config_decorator'; import {routeregistry} 'angular2/src/router/route_registry'; import {directiveresolver} 'angular2/src/core/linker/directive_resolver';  beforeeachproviders(() => {         return [             routeregistry,             provide(location, { useclass: spylocation }),             provide(router_primary_component, { usevalue: yourcomponentwithrouteconfig }),             provide(router, {useclass: rootrouter}),             formbuilder,             someinfoedit         ];     }); 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -