Skip to content

Commit

Permalink
Merge f169b8a into 173fd6d
Browse files Browse the repository at this point in the history
  • Loading branch information
mjr9804 committed Jun 14, 2021
2 parents 173fd6d + f169b8a commit 15997d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/createSvgDataURL.ts
Expand Up @@ -11,6 +11,7 @@ export function createSvgDataURL(

svg.setAttributeNS('', 'width', `${width}`)
svg.setAttributeNS('', 'height', `${height}`)
svg.setAttributeNS('', 'viewBox', `0 0 ${width} ${height}`)

foreignObject.setAttributeNS('', 'width', '100%')
foreignObject.setAttributeNS('', 'height', '100%')
Expand Down
14 changes: 14 additions & 0 deletions test/spec/index.spec.ts
Expand Up @@ -300,6 +300,20 @@ describe('html to image', () => {
.then(done)
.catch(done)
})

it('should include a viewBox attribute', (done) => {
Helper.bootstrap('small/node.html', 'small/style.css', 'small/image')
.then(htmlToImage.toSvg)
.then(Helper.getSvgDocument)
.then((doc) => {
const width = doc.documentElement.getAttribute('width')
const height = doc.documentElement.getAttribute('height')
const viewBox = doc.documentElement.getAttribute('viewBox')
expect(viewBox).toEqual(`0 0 ${width} ${height}`)
})
.then(done)
.catch(done)
})
})

describe('work with options', () => {
Expand Down

0 comments on commit 15997d6

Please sign in to comment.