Hi I am writing unit test case for my angular code. I am trying to update textbox in gridview. Below is my gridview code.
<input *ngIf="editing[rowIndex + '-scopevalue']" class="inline-editor" autofocus (blur)="updateValue($event, 'scopevalue', value, rowIndex)" type="text" [value]="value" />
Below function performs update.
updateValue(event, cell, cellValue, rowIndex) {
this.editing[rowIndex + '-' + cell] = false;
this.rows[rowIndex][cell] = event.target.value;
this.rowsCache[rowIndex][cell] = event.target.value;
this.scopeEdit = this.rows[rowIndex];
this.updateScope();
}
Below unit test case I am writing to check above code.
it('update scope name value', () => {
var row = component.rows[0];
let cell = 'scopevalue';
let cellValue = row.scopevalue;
let rowIndex = 0;
component.updateValue('/bmw', cell, cellValue, rowIndex);
});
In the above method, first parameter supposed to be event. Can someone help me how to create event? Any help would be appreciated. Thank you
event.target.value
and verify in yourupdateValue
function ifrowsCache[rowIndex][cell]
will have that value. You can mock Event with a simple object, like this :const event = { target: { value: 42 }}; component.updateValue(event, cell, cellValue, rowIndex);
– Discount