phegman / vue-mapbox-gl

A Vue.js component for Mapbox GL JS
GNU General Public License v3.0
270 stars 33 forks source link

Error: when testing with `jest` #82

Open AchoArnold opened 4 years ago

AchoArnold commented 4 years ago

Hello,

When I try to test a mapbox componet with jest, I get the error Error in mounted hook: "ReferenceError: mapboxgl is not defined"

I've tried changing my jest config to

module.exports = {
    moduleNameMapper: {
        '\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
            '<rootDir>/.jest/fileMock.js',
        mapboxgl: '<rootDir>/node_modules/mapbox-gl/dist/mapbox-gl.js',
    },
};

and even adding a jest mock but I can't get it to work

jest.mock('mapboxgl', () => ({
    Map: () => ({}),
}));