UNPKG

react-oc

Version:

A React component that allows OpenComponents to operate within a react application.

56 lines (50 loc) 1.66 kB
"use strict"; var originals = { log: console.log, warn: console.warn, error: console.error }; console.log = jest.fn(console.log); console.warn = jest.fn(console.warn); console.error = jest.fn(console.error); global.suppress = { console: function (_console) { function console(_x, _x2) { return _console.apply(this, arguments); } console.toString = function () { return _console.toString(); }; return console; }(function (method, regex) { var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, _ref$always = _ref.always, always = _ref$always === void 0 ? false : _ref$always; if (!originals[method]) { throw new Error("unable to suppress unmocked method console.".concat(method)); } console[method].mockImplementation(function () { if (regex.test(arguments.length <= 0 ? undefined : arguments[0])) { // bypass console.error call. // restore mock of original fn for any further calls. if (!always) { console[method].mockImplementation(originals.error); } } else { originals[method].apply(originals, arguments); } }); }) }; console.error.suppressOnceMatching = function (regex) { console.error.mockImplementation(function () { if (regex.test(arguments.length <= 0 ? undefined : arguments[0])) { // bypass console.error call. // restore mock of original fn for any further calls. console.error.mockImplementation(originals.error); } else { originals.error.apply(originals, arguments); } }); }; //# sourceMappingURL=console-mock.js.map