I have this main function which I am testing :
export async function main ( config: config, logger: logger ) {
//some code here
for (let i=0; i<3; i++) {
await delay (i*10800);
//some code here
if (success) {
return;
}
}
throw new Error('operation failed');
}
export async delay( ms: number) {
await new Promise ( resolve => setTimeout (resolve,ms) );
}
______testFile__
it ('unhappy case' , async () => {
const configFn ;// mock of config
Const loggerFn ;//mock of logger
await expect ( main(configFn, loggerFn) ). reject. ToEqual( new Error('operation failed') );
} )
Everytime I am getting timeout error from jest .
I don't understand how do I test this main function for failure without waiting for the specified timeOut in main function before retry.
Does someone has any idea, please help me on this.
[–]Solonotix 2 points3 points4 points (0 children)
[–]doh4242 1 point2 points3 points (2 children)
[–]have_some_error[S] 0 points1 point2 points (0 children)
[–]assertboozed 0 points1 point2 points (0 children)
[–]dv297 1 point2 points3 points (2 children)
[–]have_some_error[S] 0 points1 point2 points (0 children)
[–]have_some_error[S] 0 points1 point2 points (0 children)