首页 > 解决方案 > 单元测试 SyntaxError:DOM 异常 12 角度 5

问题描述

我正在使用Angular 5 and angular material,并且在 HTML 中,当我使用ProgressSpinner并运行单元测试时,出现该错误SyntaxError: DOM Exception 12,有一个脚本

<div *ngIf="!loadingEmployees; else spinnerLoading">
  <app-contributor *ngFor="let employee of employees"></app-contributor>
</div>
<ng-template #spinnerLoading>
  <div class="loading row centralize">
    <!-- <mat-spinner color="warn" diameter="80" strokeWidth="6"></mat-spinner> -->
    <p>Loading...</p>
  </div>
</ng-template>

当我推荐脚本时,测试就会通过。在单元测试中,我只导入具有 Material 模块的 Shared 模块。像那样

  beforeEach(async(() => {
    TestBed.configureTestingModule({
      imports: [
        BrowserAnimationsModule,
        SharedModule
      ],
      providers: [
        { provide: ContributorContentService, useClass: ContributorContentServiceMock },
        { provide: MatDialog, useClass: MatDialogMock }
      ]
    })
    .compileComponents();
  }))

有人有什么想法吗?我忘记了什么?非常感谢!

标签: angularunit-testingtestingangular-materialspinner

解决方案


通过css删除diameter="80"<mat-spinner>更新直径可以帮助我解决问题。但应该是一些更好的方法。


推荐阅读