How to test a unhandledRejection / uncaughtException handler with jest

前端 未结 2 2098
旧时难觅i
旧时难觅i 2021-02-14 05:36

I have handlers for unhandledRejections and uncaughtExceptions:

bin.js

[\'unhandledRejection\', \'uncaughtExce         


        
2条回答
  •  庸人自扰
    2021-02-14 06:24

    putting it inside try catch will help:

    const error = new Error('mock error');

    try {

    await Promise.reject(error);
    

    } catch(error){

       expect(logger.error).toHaveBeenCalledWith(error);
    

    }

提交回复
热议问题