const mockExit = jest.spyOn(process, 'exit').mockImplementation(() => { throw new Error('Boom!') }) expect(myFunc(condition)).rejects.toThrow('Boom!') expect(mockExit).toHaveBeenCalledWith(ERROR_CODE) mockExit.mockRestore()