2016-10-11 20:08:54 +03:00
|
|
|
/**
|
2018-09-12 01:27:47 +03:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-10-11 20:08:54 +03:00
|
|
|
*
|
2018-02-17 05:24:55 +03:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 05:06:46 +03:00
|
|
|
*
|
|
|
|
* @format
|
2016-10-11 20:08:54 +03:00
|
|
|
*/
|
|
|
|
|
2015-04-24 23:14:24 +03:00
|
|
|
// This mock only provides short-circuited methods of applyWithGuard and guard.
|
|
|
|
// A lot of modules rely on these two functions. This mock relieves their tests
|
|
|
|
// from depending on the real ErrorUtils module. If you need real error handling
|
|
|
|
// don't use this mock.
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
function execute(fun, context, args) {
|
|
|
|
return fun.apply(context, args);
|
2015-05-19 23:43:46 +03:00
|
|
|
}
|
2015-04-24 23:14:24 +03:00
|
|
|
|
|
|
|
function reportError(error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
|
2018-05-11 01:44:52 +03:00
|
|
|
const ErrorUtils = {
|
2016-04-28 05:15:28 +03:00
|
|
|
apply: jest.fn(execute),
|
|
|
|
applyWithGuard: jest.fn(execute),
|
|
|
|
guard: jest.fn(callback => callback),
|
|
|
|
inGuard: jest.fn().mockReturnValue(true),
|
|
|
|
reportError: jest.fn(reportError),
|
|
|
|
setGlobalHandler: jest.fn(),
|
2015-04-24 23:14:24 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = ErrorUtils;
|