How to test angular2 dynamic routes

I have one issue with angular2 testing.
I have some child component with theirs own routing, route config generated dynamically from service, and when I try to test this component I got error about
non exist getter (it`s normal). But how and where I should pass this getter into process of component creataion?

My component

import {Component, Input} from 'angular2/core';
import {RouteConfig, ROUTER_DIRECTIVES, Router} from 'angular2/router';
/* ------- !Angular 2 native components  ---------*/
import {routeGeneratorInstance} from '../../config/routes/route_instructions_generator';


import {Config} from '../../config/config';
/* ------- !Config  ---------*/

const MODULE_PATH: string = `/${Config.getProdFolderName()}/modules/patients`;

@Component({
  selector: 'patients',
  template: `
    <router-outlet ></router-outlet>
  `,
  directives: [ROUTER_DIRECTIVES]
})

@RouteConfig(routeGeneratorInstance.getRoutesInstructions().patients)

export class PatientsComponent {}

and my test

import {setBaseTestProviders} from 'angular2/testing';
import {
TEST_BROWSER_PLATFORM_PROVIDERS,
TEST_BROWSER_APPLICATION_PROVIDERS
} from 'angular2/platform/testing/browser';

import { beforeEach,
beforeEachProviders,
describe,
expect,
provide,
it,
inject,
injectAsync,
TestComponentBuilder,
AsyncTestCompleter} from 'angular2/testing';

import {routeGeneratorInstance} from '../../config/routes/route_instructions_generator';
import {PatientsComponent} from './patients.component';

describe('Patients component test', () => {

  it('Should be able to test', injectAsync([TestComponentBuilder],
  (tcb: TestComponentBuilder) => {
    return tcb.createAsync(PatientsComponent).then((componentFixture) => {
      componentFixture.detectChanges();
      expect(true).toBe(true);
    });
  }));

});

Got error: Cannot read property ‘patients’ of undefined

I understand that I not passed this data into RouteConfig when I simulate component creatin, but how and where to do this? Thanks for any help!

Leave a Reply

avatar
  Subscribe  
Notify of