2020-02-03 21:55:50 +01:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Suppress React 16.8 act() warnings globally.
|
|
|
|
* The react teams fix won't be out of alpha until 16.9.0.
|
|
|
|
* https://github.com/facebook/react/issues/14769#issuecomment-514589856
|
|
|
|
*/
|
|
|
|
const consoleError = console.error; // eslint-disable-line no-console
|
|
|
|
beforeAll(() => {
|
|
|
|
jest.spyOn(console, 'error').mockImplementation((...args) => {
|
|
|
|
if (!args[0].includes('Warning: An update to %s inside a test was not wrapped in act')) {
|
|
|
|
consoleError(...args);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
export function mockUseEffects(count = 1) {
|
|
|
|
const spy = jest.spyOn(React, 'useEffect');
|
|
|
|
for (let i = 0; i < count; i++) {
|
2020-05-22 09:08:58 +02:00
|
|
|
spy.mockImplementationOnce((f) => f());
|
2020-02-03 21:55:50 +01:00
|
|
|
}
|
|
|
|
}
|