2020-05-31 13:47:57 +02:00
|
|
|
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
|
|
|
// allows you to do things like:
|
|
|
|
// expect(element).toHaveTextContent(/react/i)
|
|
|
|
// learn more: https://github.com/testing-library/jest-dom
|
|
|
|
import '@testing-library/jest-dom/extend-expect';
|
2020-06-10 15:41:41 +02:00
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
import {configure} from 'enzyme';
|
2020-06-10 15:41:41 +02:00
|
|
|
import Adapter from 'enzyme-adapter-react-16';
|
|
|
|
|
2020-06-12 15:57:30 +00:00
|
|
|
configure({adapter: new Adapter()});
|
2020-08-05 17:55:51 +00:00
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* prepares fetch api for a virtual test call
|
|
|
|
* @param response the response fetch should give you back
|
|
|
|
* @returns {jest.Mock<any, any>} a jest mock function simulating a fetch
|
|
|
|
*/
|
2020-08-05 17:55:51 +00:00
|
|
|
global.prepareFetchApi = (response) => {
|
|
|
|
const mockJsonPromise = Promise.resolve(response);
|
|
|
|
const mockFetchPromise = Promise.resolve({
|
|
|
|
json: () => mockJsonPromise,
|
|
|
|
});
|
|
|
|
return (jest.fn().mockImplementation(() => mockFetchPromise));
|
|
|
|
}
|
|
|
|
|
2020-08-12 17:50:25 +00:00
|
|
|
/**
|
|
|
|
* prepares a failing virtual fetch api call
|
|
|
|
* @returns {jest.Mock<any, any>} a jest moch function simulating a failing fetch call
|
|
|
|
*/
|
2020-08-05 17:55:51 +00:00
|
|
|
global.prepareFailingFetchApi = () => {
|
|
|
|
const mockFetchPromise = Promise.reject("myreason");
|
|
|
|
return (jest.fn().mockImplementation(() => mockFetchPromise));
|
|
|
|
}
|