Angular2 material 'md-icon' is not a known element with Karma / Jasmine

后端 未结 3 1374
孤独总比滥情好
孤独总比滥情好 2021-01-11 13:46

I\'m working on an Angular2 application using @angular/material 2.0.0-alpha.11-3 angular-cli 1.0.0-beta.19-3 karma 1.2.0 karma-jasmine 1.0.2

Running it works fine b

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-11 14:10

    Importing the MaterialModule as suggested by yurzui and creating the component after the promise is returned solved it. Thank you yurzui

    import { async, ComponentFixture, TestBed } from '@angular/core/testing';
    import { By } from '@angular/platform-browser';
    import { DebugElement } from '@angular/core';
    import { WatchpanelComponent } from './watchpanel.component';
    import { FormsModule } from '@angular/forms';
    import { MaterialModule } from '@angular/material';
    
    describe('WatchpanelComponent', () => {
      let component: WatchpanelComponent;
      let fixture: ComponentFixture;
    
      beforeEach(async(() => {
        TestBed.configureTestingModule({
          imports: [ MaterialModule.forRoot() ],
          // forRoot() deprecated
          // in later versions ------^
          declarations: [ WatchpanelComponent ] // declare the test component
        })
        .compileComponents().then(() => {
          fixture = TestBed.createComponent(WatchpanelComponent);
          component = fixture.componentInstance;
          fixture.detectChanges();
        });
    
      }));
    
      // beforeEach(() => {
      //   fixture = TestBed.createComponent(WatchpanelComponent);
      //   component = fixture.componentInstance;
      //   fixture.detectChanges();
      // });
    
      it('should create', () => {
        expect(component).toBeTruthy();
      });
    });
    

提交回复
热议问题