使用fontawesome进行的业力测试-“ @ fortawesome / free-brands-svg-icons”:“ ^ 5.10.0”,在模板中在控制台上引发错误

时间:2019-07-30 11:37:12

标签: angular

我正在为具有以下模板(包括令人敬畏的字体图标)的组件编写隔离的单元测试。

<div class="container">
  <div class="row justify-content-center">
    <div class="col text-center">
      <span id="copyright">All rights reserved. Copyright @ 2019</span>
    </div>
  </div>
  <div class="row justify-content-center">
    <a class="col-sm-2" href="">
      <fa-icon [icon]="['fab', 'blogger']" class="border-bottom" [spin]="true"></fa-icon>
    </a>
    <a class="col-sm-2" href="">
      <fa-icon [icon]="['fab', 'twitter']" class="border-bottom" [spin]="true"></fa-icon>
    </a>
    <a class="col-sm-2" href="">
      <fa-icon [icon]="['fab', 'linkedin']" [pulse]="true" class="border-bottom"></fa-icon>
    </a>
    <a class="col-sm-2" href="">
      <fa-icon [icon]="['fab', 'git']" [spin]="true" class="border-bottom"></fa-icon>
    </a>
  </div>
</div>

package.json中的版本如下

"@fortawesome/angular-fontawesome": "^0.4.0",
"@fortawesome/fontawesome-svg-core": "^1.2.20",
    "@fortawesome/free-brands-svg-icons": "^5.10.0",
    "@fortawesome/free-solid-svg-icons": "^5.10.0",

我的应用程序运行正常,但是执行简单测试时,控制台出现错误

ERROR: 'FontAwesome: Could not find icon with iconName=blogger and prefix=fab'
Chrome 74.0.3729 (Mac OS X 10.14.6): Executed 5 of 14 SUCCESS (0 secs / 0.37 secs)
ERROR: 'FontAwesome: Could not find icon with iconName=twitter and prefix=fab'
Chrome 74.0.3729 (Mac OS X 10.14.6): Executed 5 of 14 SUCCESS (0 secs / 0.37 secs)
ERROR: 'FontAwesome: Could not find icon with iconName=linkedin and prefix=fab'
Chrome 74.0.3729 (Mac OS X 10.14.6): Executed 5 of 14 SUCCESS (0 secs / 0.37 secs)
ERROR: 'FontAwesome: Could not find icon with iconName=git and prefix=fab'

我已经添加了模块

imports: [FontAwesomeModule]

尽管测试通过了,但是控制台错误仍然存​​在。

我只是在寻找确保错误消失并了解将这些图标定义添加到组件的正确方法的选项。

1 个答案:

答案 0 :(得分:2)

对于模板错误,没有必要包含引发错误的模块。您可以使用list1 = [1.913, 13.06, 24.041, 34.972] list2 = [0, 22, 36, 50]

来忽略模板上的多个模块错误

在您的spec.ts文件中

NO_ERRORS_SCHEMA from @angular/core