Reputation: 63
I just start learn using jasmine. I am confused if I need testing function which the value is the function as well, like this is the case on component.ts
validationLoadListDownload() {
if (this.getGroupId === 0) {
this.loadListDownloadRequest();
} else {
this.loadListDownloadRequestGroup();
}
}
if like that, how do we write it on component.spec.ts? I am confused, thank you
Upvotes: 0
Views: 84
Reputation: 597
it can be done something like this;
it('should download the validation list when getGroupId is zero', () => {
const loadListDownloadRequestSpy = spyOn(component, 'loadListDownloadRequest');
component.getGroupId = 0;
component.validationLoadListDownload();
expect(loadListDownloadRequestSpy).toHaveBeenCalled();
});
it('should download the validation list when getGroupId is not zero', () => {
const loadListDownloadRequestGroupSpy = spyOn(component, 'loadListDownloadRequestGroup');
component.getGroupId = 5;
component.validationLoadListDownload();
expect(loadListDownloadRequestGroupSpy ).toHaveBeenCalled();
});
Upvotes: 1