Angular 测试文档中"errorMessage()"哪些内容起作用。(见说明)



我找不到有关errorMessage()函数的任何来源或解释:

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

您能帮我整理一下,其中包含什么?

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- unzip the文件testing.zip然后转到此目录: testingsrcapptwain

3- 打开文件twain.component.spec

因此,您将在文件顶部找到辅助功能errorMessage(),甚至您在问题中给出的链接所指的链接。

最新更新