“CUSTOM_ELEMENTS_SCHEMA” Errors in Testing Angular 2 App

后端 未结 2 1602
一生所求
一生所求 2021-02-19 01:11

In writing tests for my Angular 2 app, I am running into these errors: the selectors we\'re using:

\"): AppComponent@12:35 \'tab-view\' is not a known element:
1         


        
2条回答
  •  梦谈多话
    2021-02-19 01:51

    It works for me this way, in your spec.ts file you have to import your components and needs to add it to declarations. In my case its in about.component.spec.ts

    import { async, ComponentFixture, TestBed } from '@angular/core/testing';
    import { AboutComponent } from './about.component';
    import { SidebarComponent } from './../sidebar/sidebar.component';
    import { FooterComponent } from './../footer/footer.component';
    
    describe('AboutComponent', () => {
      let component: AboutComponent;
      let fixture: ComponentFixture;
    
      beforeEach(async(() => {
        TestBed.configureTestingModule({
           declarations: [ AboutComponent, SidebarComponent, FooterComponent ]
        })
        .compileComponents();
      }));
    
      beforeEach(() => {
        fixture = TestBed.createComponent(AboutComponent);
        component = fixture.componentInstance;
        fixture.detectChanges();
      });
    
      it('should create', () => {
        expect(component).toBeTruthy();
      });
    });
    

提交回复
热议问题