1

我对 angular2 测试有一个问题。我有一些子组件有自己的路由,路由配置从服务动态生成,当我尝试测试这个组件时,我收到关于不存在 getter 的错误(这是正常的)。但是我应该如何以及在哪里将这个 getter 传递到组件创建过程中呢?

我的组件

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 {}

和我的测试

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);
    });
  }));

});

出现错误: 无法读取未定义的属性“患者”

我知道在模拟组件创建时我没有将此数据传递给 RouteConfig,但是如何以及在何处执行此操作?谢谢你的帮助!

4

0 回答 0