Skip to content

Commit e504bfb

Browse files
committed
Add test setup to make Leaflet think JSDOM supports SVG
1 parent be2cac2 commit e504bfb

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

jest.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ module.exports = {
55
coverageDirectory: 'coverage',
66
restoreMocks: true,
77
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
8+
setupFiles: [
9+
'<rootDir>/tests/setup.js'
10+
],
811
transform: {
912
'^.+\\.vue$': 'vue-jest',
1013
'.+\\.(css|styl|less|sass|scss|svg|png|jpg|ttf|woff|woff2)$':

tests/setup.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Perform any pre-test setup required.
2+
3+
// Trick Leaflet into thinking that JSDOM has SVG support.
4+
// See: https://stackoverflow.com/a/54384719/607408
5+
const createElementNSOrig = global.document.createElementNS;
6+
global.document.createElementNS = function (uri, name) {
7+
const element = createElementNSOrig.apply(this, arguments);
8+
if (uri === 'http://www.w3.org/2000/svg' && name === 'svg') {
9+
element.createSVGRect = function () {};
10+
}
11+
12+
return element;
13+
};

0 commit comments

Comments
 (0)