如何解决如何测试角度材料对话框是否打开
我正在编写一个单元测试,以检查函数调用是否打开了Material对话框元素。我得到False,而预期结果为True。组件功能是:
x.component.ts
openCartDialog(): void {
this.dialog.open(CartComponent);
this.isCartDialogopen = true;
}
我的x.component.spec.ts文件具有以下代码并进行测试:
export class DialogMock {
open(): void {
return;
}
}
beforeEach(async(() => {
Testbed.configureTestingModule({
declarations: [MainPageComponent,CartComponent,ConfirmButtonComponent],imports: [RouterTestingModule,HttpClientModule,MatTabsModule,MatDialogModule],providers: [
{ provider: MatDialog,useClass: DialogMock },],}).compileComponents();
}));
beforeEach(() => {
fixture = Testbed.createComponent(MainPageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should open the cart dialog',() => {
component.openCartDialog();
expect(component.isCartDialogopen).toBeTrue();
});
我认为问题出在我的beforeEach()上,其中CartComponent没有正确实例化。购物车组件还在模板中使用其他组件...在此代码中我仅包含ConfirmButtonComponent,但还有更多。
感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。