I need help writing tests for the following code using jest:
@Debounce(100)
private checkDataToPositionInStep(): void {
const proposalConsultData = this.proposalConsultResponseStore.get();
if(proposalConsultData?.documentProposalData?.length > 1) {
this.fullScreenLoaderService.hideLoader();
this.router.navigate(['proposta-enviada']);
return;
}
if(proposalConsultData?.warrantyData?.plateUf) {
this.fullScreenLoaderService.hideLoader();
this.router.navigate(['upload']);
}
if(proposalConsultData?.bankData?.branchCode) {
this.fullScreenLoaderService.hideLoader();
this.scrollService.next(STEP_ACCORDION.DADOS_GARANTIA.STEP);
this.stepperService.next(STEP_ACCORDION.DADOS_GARANTIA.ID);
return;
}
this.fullScreenLoaderService.hideLoader();
this.scrollService.next(STEP_ACCORDION.DADOS_BANCARIOS.STEP);
this.stepperService.next(STEP_ACCORDION.DADOS_BANCARIOS.ID);
return;
}
The debounce decorator used is defined as follows:
export function Debounce(timeout: number): Function {
return function (target, propertyKey: string, descriptor: PropertyDescriptor) {
const original = descriptor.value;
descriptor.value = function debounce(...args) {
setTimeout(() => {
original.apply(this, args);
}, timeout);
}
return descriptor;
}
}
When running npm run:coverage
, all lines below decorators are not being covered. Is there a way to cover these lines?
I attempted to test the checkDataToPositionInStep method like this:
it('Should call checkDataToPositionInStep with only bankData', () => {
const proposalConsultMock = <any> {
bankData: {
branchCode: '01901'
}
};
(facade as any).checkDataToPositionInStep(proposalConsultMock );
});
I expected jest to cover the checkDataToPositionInStep method.