[英]how to write unit test to cover all the condition of breakpoint observer?
我嘗試編寫單元測試斷點觀察器。 但陽性條件不包括在內
isSmallScreen: Observable<BreakpointState> = this.breakpointObserver.observe('(max-width: 767px)');
openEntityDetailDialog(): void {
this.entityCreationComponent.close();
this.dialogRef = this.dialog.open(HomeBusinessEntityDetail, {
maxWidth: '767px', disableClose: true
});
const dialogSubscription = this.isSmallScreen.subscribe(result => {
if (result.matches) {
this.dialogRef.updateSize('100%', '100%');
} else {
this.dialogRef.updateSize('560px');
}
});
this.dialogRef.afterClosed().subscribe(result => {
dialogSubscription.unsubscribe();
});
}
幫我寫行的單元測試
const dialogSubscription = this.isSmallScreen.subscribe(result => {
if (result.matches) {
this.dialogRef.updateSize('100%', '100%');
}
提前致謝。
你可以試試這樣的
it('should update the dialog size', () => {
component.isSmallScreen = of({ matches: true });
const spy: Jasmine.Spy = spyOn(component.dialogRef, 'updateSize'); // considering you have mocked the dialogRef in your test
component.openEntityDetailDialog();
expect(spy).toHaveBeenCalledWith('100%', '100%');
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.