【发布时间】:2019-05-08 11:52:17
【问题描述】:
我正在尝试对这个材质对话框进行单元测试,以测试模板是否呈现正确的注入对象。正确使用组件可以正常工作
组件 - 对话框
export class ConfirmationDialogComponent {
constructor(@Inject(MAT_DIALOG_DATA) private dialogModel: ConfirmationDialogModel) {}
}
对话框模板
<h1 mat-dialog-title *ngIf="dialogModel.Title">{{dialogModel.Title}}</h1>
<div mat-dialog-content>
{{dialogModel.SupportingText}}
</div>
<div mat-dialog-actions>
<button mat-button color="primary" [mat-dialog-close]="false">Cancel</button>
<button mat-raised-button color="primary"[mat-dialog-close]="true" cdkFocusInitial>{{dialogModel.ActionButton}}</button>
</div>
模型 - 注入什么
export interface ConfirmationDialogModel {
Title?: string;
SupportingText: string;
ActionButton: string;
}
单元测试 - 我遇到问题的地方
describe('Confirmation Dialog Component', () => {
const model: ConfirmationDialogModel = {
ActionButton: 'Delete',
SupportingText: 'Are you sure?',
};
let component: ConfirmationDialogComponent;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ConfirmationDialogComponent
],
imports: [
MatButtonModule,
MatDialogModule
],
providers: [
{
// I was expecting this will pass the desired value
provide: MAT_DIALOG_DATA,
useValue: model
}
]
});
component = TestBed.get(ConfirmationDialogComponent);
}));
it('should be created', async(() => {
expect(component).toBeTruthy();
}));
});
业力错误
【问题讨论】:
标签: angular unit-testing karma-jasmine angular-material2 angular-test