【问题标题】:What contents "errorMessage()" function in Angular testing docs. (see the description)Angular 测试文档中的“errorMessage()”函数的内容。 (见说明)
【发布时间】:2018-08-09 02:38:51
【问题描述】:

我找不到任何关于errorMessage() 函数的来源或解释,这里写的是:

https://angular.io/guide/testing#async-test-with-fakeasync.

你能帮我整理一下,里面有什么吗?

【问题讨论】:

    标签: javascript angular unit-testing testing angular-test


    【解决方案1】:

    errorMessage()函数的代码是:

    // Helper function to get the error message element value
    // An *ngIf keeps it out of the DOM until there is an error
    const errorMessage = () => {
      const el = fixture.nativeElement.querySelector('.error');
      return el ? el.textContent : null;
    };
    

    要查找此代码:

    1- 从这里下载测试代码示例:

    https://angular.io/guide/testing#async-test-with-fakeasync

    所以,在页面顶部点击下载示例

    直接链接:https://angular.io/generated/zips/testing/testing.zip

    2-解压testing.zip文件,进入这个目录:\testing\src\app\twain

    3-打开文件twain.component.spec

    所以你会在文件顶部找到帮助函数errorMessage(),甚至是你在问题中给出的链接所指的测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多