UNPKG

968 BTypeScriptView Raw
1import { mount } from 'enzyme';
2import * as React from 'react';
3import { MapContext } from '../context';
4import * as MapboxGl from 'mapbox-gl';
5
6// tslint:disable-next-line:no-any
7export const getMapMock = (override?: { [key: string]: any }) => ({
8 addSource: jest.fn(),
9 removeSource: jest.fn(),
10 addLayer: jest.fn(),
11 on: jest.fn(),
12 off: jest.fn(),
13 setLayerZoomRange: jest.fn(),
14 getLayer: jest.fn(),
15 addImage: jest.fn(),
16 loadImage: jest.fn(),
17 removeImage: jest.fn(),
18 hasImage: jest.fn(),
19 getSource: jest.fn().mockReturnValue({ setData: jest.fn() }),
20 project: jest.fn(),
21 ...override
22});
23
24// tslint:disable-next-line:no-any
25export const mountWithMap = (comp: JSX.Element, mapValue: any) => {
26 return mount(
27 <MapContext.Provider value={mapValue}>{comp}</MapContext.Provider>
28 );
29};
30
31export class MockComponent extends React.Component<{
32 id: string;
33 map: MapboxGl.Map;
34}> {
35 public render() {
36 return <h1>{this.props.id}</h1>;
37 }
38}