2017-09-28 14:25:49 +02:00
|
|
|
import 'jest-enzyme/lib/index';
|
|
|
|
|
|
|
|
// setup file
|
|
|
|
import { configure } from 'enzyme';
|
|
|
|
import Adapter from 'enzyme-adapter-react-16';
|
2019-05-06 12:44:58 +02:00
|
|
|
import regeneratorRuntime from 'regenerator-runtime';
|
2017-09-28 14:25:49 +02:00
|
|
|
|
2018-06-12 21:50:13 +03:00
|
|
|
import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
|
|
|
|
|
|
|
|
registerRequireContextHook();
|
|
|
|
|
2019-03-18 21:28:00 +01:00
|
|
|
jest.mock('util-deprecate', () => fn => fn);
|
|
|
|
|
2017-11-19 18:22:46 -05:00
|
|
|
// mock console.info calls for cleaner test execution
|
2017-11-21 04:18:36 +03:00
|
|
|
global.console.info = jest.fn().mockImplementation(() => {});
|
2019-03-18 21:28:00 +01:00
|
|
|
global.console.debug = jest.fn().mockImplementation(() => {});
|
2017-11-19 18:22:46 -05:00
|
|
|
|
2018-11-11 22:43:05 -08:00
|
|
|
// mock local storage calls
|
|
|
|
const localStorageMock = {
|
2018-11-11 23:11:57 -08:00
|
|
|
getItem: jest.fn().mockName('getItem'),
|
|
|
|
setItem: jest.fn().mockName('setItem'),
|
|
|
|
clear: jest.fn().mockName('clear'),
|
2018-11-11 22:43:05 -08:00
|
|
|
};
|
|
|
|
global.localStorage = localStorageMock;
|
2019-05-06 12:44:58 +02:00
|
|
|
global.regeneratorRuntime = regeneratorRuntime;
|
2018-11-11 22:43:05 -08:00
|
|
|
|
2017-09-28 14:25:49 +02:00
|
|
|
configure({ adapter: new Adapter() });
|
2017-11-12 13:40:07 -05:00
|
|
|
|
|
|
|
/* Fail tests on PropType warnings
|
2019-01-03 13:13:59 +01:00
|
|
|
This allows us to throw an error in tests environments when there are prop-type warnings.
|
|
|
|
This should keep the tests free of warnings going forward.
|
2017-11-12 13:40:07 -05:00
|
|
|
*/
|
|
|
|
|
2019-01-03 13:13:59 +01:00
|
|
|
const ignoreList = [
|
2019-02-06 17:38:59 +01:00
|
|
|
error => error.message.includes('":nth-child" is potentially unsafe'),
|
2019-01-03 13:13:59 +01:00
|
|
|
error => error.message.includes('":first-child" is potentially unsafe'),
|
|
|
|
error => error.message.includes('Failed prop type') && error.stack.includes('storyshots'),
|
2019-09-24 13:11:17 +02:00
|
|
|
error =>
|
|
|
|
error.message.includes('react-async-component-lifecycle-hooks') &&
|
|
|
|
error.stack.includes('addons/knobs/src/components/__tests__/Options.js'),
|
2018-12-21 17:10:38 +01:00
|
|
|
];
|
|
|
|
|
2019-01-03 20:56:48 +01:00
|
|
|
const throwMessage = (type, message) => {
|
|
|
|
const error = new Error(`${type}${message}`);
|
2019-01-03 13:13:59 +01:00
|
|
|
if (!ignoreList.reduce((acc, item) => acc || item(error), false)) {
|
|
|
|
throw error;
|
2018-12-21 17:10:38 +01:00
|
|
|
}
|
2017-11-12 13:40:07 -05:00
|
|
|
};
|
2019-01-03 20:56:48 +01:00
|
|
|
const throwWarning = message => throwMessage('warn: ', message);
|
|
|
|
const throwError = message => throwMessage('error: ', message);
|
2017-11-12 13:40:07 -05:00
|
|
|
|
|
|
|
global.console.error = throwError;
|
2019-01-03 20:56:48 +01:00
|
|
|
global.console.warn = throwWarning;
|