From b75c7c69776ff82f6fa7b11529d98fd69d7001e5 Mon Sep 17 00:00:00 2001 From: Moriz Wahl Date: Thu, 23 Feb 2023 18:13:19 +0100 Subject: [PATCH] hack MapboxGeocoder in unit tests by simply stubbing the import --- webapp/jest.config.js | 4 ++-- webapp/pages/map.spec.js | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/webapp/jest.config.js b/webapp/jest.config.js index 1b3f4d03e..42110ba3b 100644 --- a/webapp/jest.config.js +++ b/webapp/jest.config.js @@ -20,16 +20,16 @@ module.exports = { transform: { '.*\\.(vue)$': 'vue-jest', '^.+\\.js$': 'babel-jest', - '/node_modules/@mapbox/mapbox-gl-geocoder/dist/*': 'babel-jest', }, testMatch: ['**/?(*.)+(spec|test).js?(x)'], modulePathIgnorePatterns: ['/build/'], moduleNameMapper: { '\\.(svg)$': '/test/fileMock.js', '\\.(css|less)$': 'identity-obj-proxy', + '@mapbox/mapbox-gl-geocoder': 'identity-obj-proxy', '^@/(.*)$': '/src/$1', '^~/(.*)$': '/$1', }, moduleFileExtensions: ['js', 'json', 'vue'], - testEnvironment: 'jsdom', + testEnvironment: 'jest-environment-jsdom', } diff --git a/webapp/pages/map.spec.js b/webapp/pages/map.spec.js index 5dbb34cf8..a9e21c876 100644 --- a/webapp/pages/map.spec.js +++ b/webapp/pages/map.spec.js @@ -4,8 +4,11 @@ import { mount } from '@vue/test-utils' import VueMeta from 'vue-meta' import Vuex from 'vuex' import Map from './map' +import MapboxGeocoder from '@mapbox/mapbox-gl-geocoder' -jest.mock('@mapbox/mapbox-gl-geocoder') +jest.mock('@mapbox/mapbox-gl-geocoder', () => { + return jest.fn().mockImplementation(jest.fn()) +}) jest.mock('mapbox-gl', () => { return { @@ -70,6 +73,7 @@ describe('map', () => { let mocks beforeEach(() => { + MapboxGeocoder.mockClear() mocks = { $t: (t) => t, $env: { @@ -97,7 +101,7 @@ describe('map', () => { }) it('renders', () => { - expect(wrapper.is('div')).toBeTruthy() + expect(wrapper.element.tagName).toBe('DIV') }) it('has correct content', () => {