Skip to content

Commit

Permalink
fix: multiple define on cached native object in jest
Browse files Browse the repository at this point in the history
  • Loading branch information
nomagick authored and Brooooooklyn committed Jan 1, 2023
1 parent b97553d commit 88f5ee9
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions index.js
Expand Up @@ -31,20 +31,24 @@ const SvgExportFlag = {
// eslint-disable-next-line sonarjs/no-unused-collection
const Fonts = []

Object.defineProperty(GlobalFonts, 'families', {
get: function () {
return JSON.parse(GlobalFonts.getFamilies())
},
})
if (!('families' in GlobalFonts)) {
Object.defineProperty(GlobalFonts, 'families', {
get: function () {
return JSON.parse(GlobalFonts.getFamilies())
},
})
}

Object.defineProperty(GlobalFonts, 'has', {
value: function has(name) {
return !!JSON.parse(GlobalFonts.getFamilies()).find(({ family }) => family === name)
},
configurable: false,
enumerable: false,
writable: false,
})
if (!('has' in GlobalFonts)) {
Object.defineProperty(GlobalFonts, 'has', {
value: function has(name) {
return !!JSON.parse(GlobalFonts.getFamilies()).find(({ family }) => family === name)
},
configurable: false,
enumerable: false,
writable: false,
})
}

function createCanvas(width, height, flag) {
const isSvgBackend = typeof flag !== 'undefined'
Expand Down

0 comments on commit 88f5ee9

Please sign in to comment.