相关疑难解决方法(0)

单元测试带有导入模块的angular2组件

我试图在使用angular-material2的组件上编写测试,但是当我将它添加到我的testModule声明时,我得到:

Error: Template parse errors:
    'md-card-title' is not a known element:
    1. If 'md-card-title' is an Angular component, then verify that it is part of this module.
    2. If 'md-card-title' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schemas' of this component to suppress this message.
Run Code Online (Sandbox Code Playgroud)

将MaterialModule添加到声明中会抛出`错误:模块声明的意外模块'MaterialModule'

config/spec-bundle.js中的DynamicTestModule'(第24994行)

这是我的spec文件的样子:

  beforeEach(() => TestBed.configureTestingModule({
    declarations: [],
    providers: [
      { provide: DataService, useValue: mockDataService },
      { provide: ActivatedRoute, useClass: MockActivatedRoute },
      { provide: Router, useValue: mockRouter },
      CellViewComponent
    ]
  }));
Run Code Online (Sandbox Code Playgroud)

添加CellViewComponent …

typescript karma-jasmine angular2-testing angular-material2 angular

10
推荐指数
2
解决办法
1万
查看次数