hack MapboxGeocoder in unit tests by simply stubbing the import

This commit is contained in:
Moriz Wahl 2023-02-23 18:13:19 +01:00
parent 4ac3d21e2a
commit b75c7c6977
2 changed files with 8 additions and 4 deletions

View File

@ -20,16 +20,16 @@ module.exports = {
transform: {
'.*\\.(vue)$': 'vue-jest',
'^.+\\.js$': 'babel-jest',
'<rootDir>/node_modules/@mapbox/mapbox-gl-geocoder/dist/*': 'babel-jest',
},
testMatch: ['**/?(*.)+(spec|test).js?(x)'],
modulePathIgnorePatterns: ['<rootDir>/build/'],
moduleNameMapper: {
'\\.(svg)$': '<rootDir>/test/fileMock.js',
'\\.(css|less)$': 'identity-obj-proxy',
'@mapbox/mapbox-gl-geocoder': 'identity-obj-proxy',
'^@/(.*)$': '<rootDir>/src/$1',
'^~/(.*)$': '<rootDir>/$1',
},
moduleFileExtensions: ['js', 'json', 'vue'],
testEnvironment: 'jsdom',
testEnvironment: 'jest-environment-jsdom',
}

View File

@ -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 <head> content', () => {