Сборка работает, но не запускается "ng test" - PullRequest
0 голосов
/ 13 февраля 2020

Я получаю следующую ошибку при запуске теста ng, хотя могу запустить ng build --prod.

1. If 'app-navbar' is an Angular component, then verify that it is part of this module.
        'app-navbar' is not a known element:
        1. If 'app-navbar' is an Angular component, then verify that it is part of this module.
        2. If 'app-navbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-navbar></app-navbar>"): ng:///DynamicTestModule/AppComponent.html@0:0
        error properties: Object({ ngSyntaxError: true, ngParseErrors: [ 'app-navbar' is not a known element:
        2. If 'app-navbar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<app-navbar></app-navbar>"): ng:///DynamicTestModule/AppComponent.html@0:0 ] })
        Error: Template parse errors:
            at syntaxError (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:2175:1)
            at TemplateParser.parse (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:11388:1)
            at JitCompiler._parseTemplate (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25963:1)
            at JitCompiler._compileTemplate (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25951:61)
            at http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25895:1
            at <Jasmine>
            at JitCompiler._compileComponents (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25895:1)
            at http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25815:1
            at Object.then (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:2166:27)
            at JitCompiler._compileModuleAndAllComponents (http://localhost:9877/_karma_webpack_/node_modules/@angular/compiler/fesm2015/compiler.js:25813:1)

, если у меня есть компонент navbar вне общей папки, работает тест ng. но при выполнении больших проектов мне нужно поместить компоненты в разные папки, например, core, shared, data.

1 Ответ

1 голос
/ 13 февраля 2020

Вам необходимо добавить этот компонент или модуль, содержащий этот компонент, в объявлении теста следующим образом:

beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [AppNavBar],
      imports: [RouterTestingModule]
    })
    .compileComponents();
  }));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...