Skip to content

Instantly share code, notes, and snippets.

@paveltretyakovru
Created October 26, 2021 23:54
Show Gist options
  • Save paveltretyakovru/565c17a5934a2b0700bb626842dc0a43 to your computer and use it in GitHub Desktop.
Save paveltretyakovru/565c17a5934a2b0700bb626842dc0a43 to your computer and use it in GitHub Desktop.
Setups for Jest tests of CRA application to fix TypeError: window.URL.createObjectURL is not a function
// react-testing-library renders your components to document.body,
// this adds jest-dom's custom assertions
import '@testing-library/jest-dom/extend-expect';
import 'react-app-polyfill/ie11';
import 'react-app-polyfill/stable';
import 'jest-styled-components';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
// fix to TypeError: window.URL.createObjectURL is not a function
jest.mock('mapbox-gl/dist/mapbox-gl', () => ({
GeolocateControl: jest.fn(),
Map: jest.fn(() => ({
addControl: jest.fn(),
on: jest.fn(),
remove: jest.fn(),
})),
NavigationControl: jest.fn(),
}));
configure({ adapter: new Adapter() });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment