-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wait for svg before firing onLoad, add transformSrc test
- Loading branch information
robinscholz
committed
May 13, 2020
1 parent
7bdf066
commit d331626
Showing
4 changed files
with
42 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,52 @@ | ||
import { render } from '@testing-library/svelte' | ||
import { render, waitFor } from '@testing-library/svelte' | ||
import InlineSVG from '../inline-svg.svelte' | ||
|
||
const src = 'https://raw.githubusercontent.com/robinscholz/svelte-inline-svg/master/src/test/test.svg' | ||
const src = | ||
'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MCA1MCI+CiAgPHJlY3Qgd2lkdGg9IjUwIiBoZWlnaHQ9IjUwIi8+Cjwvc3ZnPg==' | ||
|
||
describe('inline-svg', () => { | ||
test('render component correctly', () => { | ||
const { container } = render(InlineSVG, { | ||
props: { | ||
src: src | ||
} | ||
src: src, | ||
}, | ||
}) | ||
|
||
expect(container).toContainHTML('<svg') | ||
expect(container).toContainHTML('svg') | ||
}) | ||
|
||
test('has width set', () => { | ||
const { container } = render(InlineSVG, { | ||
props: { | ||
src: src, | ||
width: 50, | ||
} | ||
}, | ||
}) | ||
const element = container.querySelector('svg') | ||
expect(element).toHaveAttribute('width') | ||
}) | ||
|
||
test('transformSrc is working', async () => { | ||
const doc = document | ||
const transform = (svg) => { | ||
let point = doc.createElementNS('http://www.w3.org/2000/svg', 'circle') | ||
point.setAttributeNS(null, 'cx', '20') | ||
point.setAttributeNS(null, 'cy', '20') | ||
point.setAttributeNS(null, 'r', '10') | ||
point.setAttributeNS(null, 'fill', 'red') | ||
svg.appendChild(point) | ||
return svg | ||
} | ||
const { container } = render(InlineSVG, { | ||
props: { | ||
src: src, | ||
transformSrc: transform, | ||
}, | ||
}) | ||
|
||
const element = container.querySelector('svg') | ||
await waitFor(() => { | ||
expect(element).toContainHTML('circle') | ||
}) | ||
}) | ||
}) |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.