Skip to content

Error: when testing with jest #82

@AchoArnold

Description

@AchoArnold

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions