我无法找到有关此处编写的 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- 解压缩文件 testing.zip 并转到此目录:\testing\src\app\twain
3- 打开文件twain.component.spec
因此您会在文件顶部找到辅助函数 errorMessage()
,甚至是您在问题中给出的链接所指的测试。
关于javascript - Angular 测试文档中 "errorMessage()"功能的内容。 (见说明),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49042730/