运行ng-test

时间:2018-04-06 16:13:34

标签: javascript angular unit-testing typescript

失败:模板解析错误:'app-navbar'不是已知元素

  1. 如果'app-navbar'是Angular组件,请验证它是否是此模块的一部分。

  2. 如果'app-navbar'是Web组件,则将'CUSTOM_ELEMENTS_SCHEMA'添加到此组件的'@ NgModule.schemas'以禁止显示此消息:

  3.   

    (“[错误 - >]< app-navbar>< / app-navbar>”):   NG:///DynamicTestModule/AppComponent.html@0:0   错误:模板解析错误:

1 个答案:

答案 0 :(得分:1)

这些错误通常意味着您没有在模块中声明组件。 您需要在测试模块中包含app-navbar ,否则,父组件不会意识到其子项的存在,因此 - 它“不是已知元素”。

在此处查看有关模块的更多信息:https://angular.io/guide/ngmodules

// Import it in your test
import { NavBar } from '<location>';

beforeEach(() => {
  TestBed.configureTestingModule({
    ...,
    // Add the child element to the declarations
    declarations: [ Navbar ],
    ...
  });
});
相关问题