[英]Custom Pipe causes the ExpressionChangedAfterItHasBeenCheckedError when running a unit test
在我的模板中,我有这个:
...
<tbody>
<ng-container *ngFor="let item of items">
<tr *ngIf="item.isBoolean">
<td><a href="#">{{item.description}}</a></td>
<td>{{item | customPipe}}</td>
</tr>
</ng-container>
</tbody>
...
这是我的单元测试:
it('should behave...', () => {
const trs: DebugElement[] = fixture.debugElement.queryAll(By.css('tbody tr'));
expect(trs.length).toBeGreaterThan(0);
});
当我执行测试时,我得到以下信息:
Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'value'. Current value: 'undefined'.. Find more at https://angular.io/errors/NG0100
error properties: Object({ code: '100' })
Error: NG0100: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'value'. Current value: 'undefined'.. Find more at https://angular.io/errors/NG0100
at throwErrorIfNoChangesMode (node_modules/@angular/core/fesm2015/core.js:6723:1)
at bindingUpdated (node_modules/@angular/core/fesm2015/core.js:12854:1
该value
是customPipe
返回的值。
我今天在通过Jasmine
测试我的 Angular 应用程序时遇到了这个问题。 请检查下面解决我的问题的代码片段(礼貌: https://www.codegrepper.com )。
import { ChangeDetectorRef, AfterContentChecked } from '@angular/core';
constructor(private ref: ChangeDetectorRef){}
ngAfterContentChecked() {
this.ref.detectChanges();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.