javascript - stubbing process.exit with jest -


i have code like

 function myfunc(condition){   if(condition){     process.exit(error_code)   }  } 

how can test in jest? overwriting exit in process jest.fn() , returning after test doesn't work, since process exits

you use jest.spyon call original method well:

const exit = jest.spyon(process, 'exit'); //run test expect(exit).tohavebeencalledwith('error_code'); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -