0
I’m having trouble testing a method of select, that’s the method:
select(task): any {
(document.getElementById(task) as HTMLInputElement).select();
};
It is called by html, in this part here:
<button id="button-edit" mat-icon-button aria-label="Alterar" *ngIf="!row.canEdit" (click)="select(row.name)" (click)="checkEdit(row)">
<mat-icon>edit</mat-icon>
</button>
My test is like this for now:
it('should select a task', () => {
const getElementById = spyOn(document, 'getElementById');
component.select(task[0].name);
expect(getElementById).toHaveBeenCalled();
});
I get the following Exception:
TypeError: Cannot read property 'select' of null
It worked, thank you very much!
– accelerate