3

I am currently trying to test a Component wrapped with third party library which is react-map-gl marker.

It keep throwing error like project undefined. so I looked into the react-map-gl code.

let [x, y] = this._context.viewport.project([longitude, latitude]);

Then, I went to see how react-map-gl test its own stuff. Then, I tried to miminc how they do. But it just timeout no matter how much time I put. Am I missing something?

import {_MapContext as MapContext} from 'react-map-gl'
import WebMercatorViewport from 'viewport-mercator-project'

const mockStaticContext = {
  viewport: new WebMercatorViewport({
    width: 800,
    height: 600,
    longitude: -122.58,
    latitude: 37.74,
    zoom: 14
  })
};
const mockInteractiveContext = Object.assign({}, mockStaticContext, {
  eventManager: {
    on: sinon.spy(),
    off: sinon.spy(),
    watch: sinon.spy()
  }
})
describe('<ListingMarker />', () => {

  it('should not explode', async (t) => {

    render(
      <MapContext.Provider value={mockInteractiveContext}>
        <AppMarker cluster={marker} />
      </MapContext.Provider>
    )
  }, 30000)


})

I tried to follow their way of testing. https://github.com/visgl/react-map-gl/blob/master/test/src/components/marker.spec.js

fiddlest
  • 1,262
  • 2
  • 17
  • 42

0 Answers0