samedi 2 septembre 2017

Angular 2 Testing - Issue with RouterLinkWithHref

I am dealing with a testing on a routed component, I am always gettings, I guess a probably have to import some more modules or provide something but I don't manage to make it works properly ? Here below the error and the code...

TypeError: Cannot read property 'subscribe' of undefined at new RouterLinkWithHref (/node_modules/@angular/router/@angular/router.es5.js:5028:1) at createClass (/node_modules/@angular/core/@angular/core.es5.js:10926:1) at createDirectiveInstance (/node_modules/@angular/core/@angular/core.es5.js:10751:22) at createViewNodes (/node_modules/@angular/core/@angular/core.es5.js:12187:34) at callViewAction (/node_modules/@angular/core/@angular/core.es5.js:12633:1) at execComponentViewsAction (/node_modules/@angular/core/@angular/core.es5.js:12542:1) at createViewNodes (/node_modules/@angular/core/@angular/core.es5.js:12214:1) at callViewAction (/node_modules/@angular/core/@angular/core.es5.js:12633:1) at execComponentViewsAction (/node_modules/@angular/core/@angular/core.es5.js:12542:1) at createViewNodes (/node_modules/@angular/core/@angular/core.es5.js:12214:1)

Here's the code of the testing module

describe('ItemsComponent', () => {
    let component: ItemsComponent;
    let fixture: ComponentFixture<ItemsComponent>;
    let store: Store<any>;
    const mockRouter = {
        navigate: jasmine.createSpy('#/items')
    }

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            imports: [
                FormsModule,
                ReactiveFormsModule,
                ItemsRoutingModule,
                MenuModule,
                MenuBottomModule,
                AutoCompleteModule,
                HttpModule,
                StoreModule.provideStore(reducer),
                RouterStoreModule.connectRouter(),
                StoreDevtoolsModule.instrumentOnlyWithExtension(),
            ],
            declarations: [
                ItemsComponent,
                ItemComponent,
                ItemEditComponent,
            ],
            providers: [
                HistoryService,
                CookieService,
                ItemsService,
                Http,
                ConnectionBackend,
                RouterModule,
                { provide: Router, useValue: mockRouter },
                { provide: Store, useValue: store },
                LoadingService,
                { provide: ActivatedRoute, useValue: mockRouter },
                MessageService,
                LoginService,
                ShopsService,
                LocationStrategy,
            ]
        })
        .compileComponents();
    }));

    beforeEach(() => {
        fixture = TestBed.createComponent(ItemsComponent);
        component = fixture.componentInstance;
        store = fixture.debugElement.injector.get(Store)
        fixture.detectChanges();
    });

    it('should be created', () => {
        expect(component).toBeTruthy();
    });
});

Thanks

Aucun commentaire:

Enregistrer un commentaire