All files / jest/mocks react-native-maps.js

89.47% Statements 17/19
75% Branches 6/8
100% Functions 3/3
89.47% Lines 17/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 841x           1x                                                         37x     37x 37x       37x 177x 20x     37x       5x       37x                       1x 1x 1x 1x 1x   1x                  
const React = require('react');
 
/**
 * Props that MapView uses but must not be forwarded to DOM nodes in jsdom
 * (react-dom warns on unknown attributes).
 */
const MAP_ONLY_PROPS = new Set([
  'customMapStyle',
  'scrollEnabled',
  'zoomEnabled',
  'pitchEnabled',
  'rotateEnabled',
  'region',
  'initialRegion',
  'coordinate',
  'center',
  'radius',
  'fillColor',
  'strokeColor',
  'strokeWidth',
  'provider',
  'userInterfaceStyle',
  'mapPadding',
  'anchor',
  'tracksViewChanges',
  'tooltip',
  'identifier',
  'zIndex',
  'opacity',
  'onDeselect',
  'stopPropagation',
  'onPress',
]);
 
function stripMapOnlyProps(props) {
  Iif (!props || typeof props !== 'object') {
    return props;
  }
  const out = {};
  Iif (typeof props.onPress === 'function') {
    out.onClick = props.onPress;
  }
 
  for (const key of Object.keys(props)) {
    if (!MAP_ONLY_PROPS.has(key)) {
      out[key] = props[key];
    }
  }
  return out;
}
 
function createMockComponent(tagName) {
  return React.forwardRef(function MockComponent(
    { children, testID, ...props },
    ref,
  ) {
    return React.createElement(
      tagName,
      {
        ref,
        'data-testid': testID,
        ...stripMapOnlyProps(props),
      },
      children,
    );
  });
}
 
const MapView = createMockComponent('div');
const Marker = createMockComponent('div');
const Callout = createMockComponent('div');
const Polyline = createMockComponent('div');
const Circle = createMockComponent('div');
 
module.exports = {
  __esModule: true,
  default: MapView,
  Marker,
  Callout,
  Polyline,
  Circle,
  PROVIDER_GOOGLE: 'google',
};