1 year ago

#335918

test-img

akkas

SVG height is undefined in Vue + Quasar testing using Jest

I receive SVG as a String from API. SVG has XML header and I parse svg element from the String as follows:

const svgXml = new DOMParser().parseFromString(svg, 'image/svg+xml')
const svg = svgXml.getElementsByTagName('svg')[0]

I need the height of svg and I am doing it as follows. While running the application, there are no errors and height is retrieved correctly.

svg.height.baseVal.value

I am mocking the API response in unit tests. It is exactly the same API response, which works correctly during the normal application run. While running the unit tests, I get the following error.

Cannot read property 'baseVal' of undefined

console.log for svg shows that their is height attribute.

<svg width="942.0" height="961.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg">

I cannot find the reason why svg.height is undefined in testing. I am doing Vue/Quasar testing via Jest using following libraries

@quasar/quasar-app-extension-testing-unit-jest
@vue/test-utils

unit-testing

svg

vuejs2

quasar-framework

quasar

0 Answers

Your Answer

Accepted video resources