If '' is an Angular component, then verify that it is part of this module

前端 未结 16 3621
慢半拍i
慢半拍i 2020-12-07 14:09

I am new in Angular2. I have tried to create a component but showing an error.

This is the app.component.ts file.

import { Component } f         


        
16条回答
  •  萌比男神i
    2020-12-07 14:58

    In my case I was writing unit tests for a component that uses sub-components, and I was writing tests to make sure those subcomponents were in the template:

    it('should include the interview selection subview', () => {
        expect(fixture.debugElement.query(By.css('app-interview')))
        .toBeTruthy()  
      }); 
    

    I didn't get an error, but a warning:

    WARN: ''app-interview' is not a known element:

    1. If 'app-interview' is an Angular component, then verify that it is part of this module. WARN: ''app-interview' is not a known element:
    2. If 'app-interview' is an Angular component, then verify that it is part of this module.
    3. If 'app-interview' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.'

    Also, the subcomponent did not show inside the browser during testing.

    I used ng g c newcomponent to generate all the components, so they were already declared in the appmodule, but not the test module that for the component I was spec'ing.

    beforeEach(async(() => {
        TestBed.configureTestingModule({
          declarations: [ EditorComponent,
            InterviewComponent]
        })
        .compileComponents();
      }));
    

提交回复
热议问题