Hi I am working on angular2. I am writing unit test case for delete operation. In real time I am making API call to delete user. To unit test i have created json objecr array and I am making required operations. Below is my code for delete operation.
it('should', async(() => {
spyOn(component, 'deleteUser');
let button = fixture.debugElement.nativeElement.querySelector('deleteUser');
button.click();
fixture.whenStable().then(() => {
expect(component.deleteUser).toHaveBeenCalled();
})
alert(1);
}));
Below is my service.
deleteUserEndpoint(userid: string) {
var deleteUserUserOnboard = { result: true };
return Observable.of(deleteUserUserOnboard);
}
Below is my html code.
<a class="btn btn-link btn-xs" href="javascript:;" id="deleteUser" (click)="deleteUser(row)"><i class="fa fa-trash-o" aria-hidden="true"></i> {{'users.management.Delete' | translate}}</a>
I have below error.
Failed: Cannot read property 'click' of null
I am newbie to unit testing. Can someone tell me what would be the expected behavior? Also may I know am I doing something wrong here? Any help would be appreciated. Thank you.