【问题标题】:HTML image gets rendered on top of KarmaHTML 图像在 Karma 之上呈现
【发布时间】:2020-04-29 00:56:32
【问题描述】:

当我运行“ng test”时,我的导航栏组件中的徽标如何在 Karma 中呈现?

运行“ng test”时,如下图所示:

以下代码来自我的 app.component.spec.ts 文件。

describe("AppComponent", () => {
  let component: AppComponent;
  let fixture: ComponentFixture<AppComponent>;
  let de: DebugElement

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        RouterTestingModule, 
        AngularFireDatabaseModule,
        AngularFireAuthModule,
        AngularFirestoreModule,
        AngularFireStorageModule,
        AngularFireModule.initializeApp( environment.firebase)],
      declarations: [
        AppComponent, 
        NavbarComponent],
      providers: 
        [ 
          DatabaseService, 
        ],
    }).compileComponents();
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(AppComponent);
    component = fixture.componentInstance;
    de = fixture.debugElement;
    fixture.detectChanges();
  });

  it("should create", () => {
    expect(component).toBeTruthy();
  });
}); 



【问题讨论】:

    标签: html angular testing karma-jasmine


    【解决方案1】:

    我猜图像出现时没有 CSS 应该有多大或多小。

    如果NavbarComponentAppComponent 的单元测试不重要,则可以使用NO_ERRORS_SCHEMA 使NavbarComponent 成为单元测试中的死HTML 元素。

    试试:

    import { NO_ERRORS_SCHEMA } from '@angular/core';
    ....
    declarations: [
            AppComponent, 
            // NavbarComponent,
       ],
    schemas: [NO_ERRORS_SCHEMA],
    
    

    那么希望图像不会出现。

    【讨论】:

      猜你喜欢
      • 2011-05-11
      • 2023-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-03
      • 1970-01-01
      • 1970-01-01
      • 2020-09-25
      相关资源
      最近更新 更多