vue-mapbox-gl icon indicating copy to clipboard operation
vue-mapbox-gl copied to clipboard

Error: when testing with `jest`

Open AchoArnold opened this issue 5 years ago • 0 comments

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: () => ({}),
}));

AchoArnold avatar Jul 16 '20 16:07 AchoArnold