【发布时间】:2022-01-07 12:47:04
【问题描述】:
【问题讨论】:
标签: angular unit-testing jasmine
【问题讨论】:
标签: angular unit-testing jasmine
下次尽量不要贴图片,自己贴代码。
这不是一个完整的答案,但它应该可以帮助您调试
it('changes to last value if invalid', async () => {
// wait for promises to complete - (1)
await fixture.whenStable();
// call fixture.detectChanges() again after promises - (2)
fixture.detectChanges()
const memberMessage = fixture.debugElement.nativeElement.querySelector('#mat-input-2');
console.log({ memberMessage }); // ensure this is not null
});
如果上述方法不起作用,请尝试使用来自here 的waitUntil 实用程序。
it('changes to last value if invalid', async () => {
// it will waitUntil the below function returns true
await waitUntil(() => !!fixture.debugElement.nativeElement.querySelector('#mat-input-2'));
const memberMessage = fixture.debugElement.nativeElement.querySelector('#mat-input-2');
console.log({ memberMessage }); // should hopefully not be null now
});
【讨论】: