[英]fixture.whenStable() is stopped working/called after upgrading from Angular 4 to 6
So I had few test cases which were checking some attributes of components (such as button).所以我很少有测试用例来检查组件的某些属性(例如按钮)。
Earlier I had test cases which used to working something like:早些时候,我有测试用例,用于工作如下:
fixture.whenStable().then(()=>{
const nextBtn = fixture.debugElement.nativeElement.querySelector(
'#create-btn'
);
console.log(nextBtn)
expect(nextBtn.getAttribute('ng-reflect-disabled')).toBe('true');;
})
suddenly, the code is not going inside fixture.whenStable().then(() => {})
, the test cases are passing with a warning such as突然,代码没有进入
fixture.whenStable().then(() => {})
,测试用例通过警告,如
SomeComponent should have button disabled has no expectations
SomeComponent 应该禁用按钮没有期望
I cant find anything over internet.我在互联网上找不到任何东西。 Has anyone faced similar issue.
有没有人遇到过类似的问题。
I also tried wrapping it around async()
of it
but no luck我也尝试将它包裹在它的
async()
周围it
但没有运气
Try to add async to beforeEach:尝试将异步添加到 beforeEach:
beforeEach(async(() => { // <-- use async
TestBed.configureTestingModule({
declarations: [AppComponent],
});
fixture = TestBed.createComponent(AppComponent);
component = fixture.componentInstance;
fixture.detectChanges();
}));
You can try following things.您可以尝试以下操作。
it('TEST', async(() => {
fixture.whenStable().then(() => {
fixture.detectChanges(); // you can write this
const nextBtn = fixture.debugElement.nativeElement.querySelector('#create-btn');
expect(nextBtn.getAttribute('ng-reflect-disabled')).toBe('true');
});
}));
for angular 11 you can wrap beforeEach's callback into waitForAsync if you want to test somesing like async ngOnInit
对于 angular 11,如果您想测试像
async ngOnInit
这样的async ngOnInit
您可以将 beforeEach 的回调包装到waitForAsync 中
beforeEach(
waitForAsync(() => {
fixture = TestBed.createComponent(SomeFeatureComponent);
component = fixture.componentInstance;
fixture.detectChanges();
})
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.