-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: split client and server side tests
- Loading branch information
Kalle Ott
committed
Jun 30, 2020
1 parent
37181eb
commit 2a9ad73
Showing
2 changed files
with
47 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** | ||
* @jest-environment node | ||
*/ | ||
import React from 'react'; | ||
import { | ||
Icon, | ||
SpriteContextProvider, | ||
IconsCache, | ||
renderSpriteSheetToString, | ||
} from '../src/index'; | ||
import { renderToString } from 'react-dom/server'; | ||
|
||
const svg1 = `<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> | ||
<path d="M0 0h24v24H0z" fill="none"/> | ||
</svg>`; | ||
const svg2 = `<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24"> | ||
<path d="M0 0h24v24H0z" fill="none"/> | ||
</svg>`; | ||
|
||
const loadSVG = async (url: string) => { | ||
switch (url) { | ||
case '1': { | ||
return svg1; | ||
} | ||
case '2': | ||
default: | ||
return svg2; | ||
} | ||
}; | ||
|
||
test('render loaded svgs to a svg sprite sheet string', async () => { | ||
const cache: IconsCache = new Map(); | ||
const renderedString = renderToString( | ||
<SpriteContextProvider knownIcons={cache} loadSVG={loadSVG}> | ||
<Icon url={'1'}></Icon> | ||
</SpriteContextProvider>, | ||
); | ||
|
||
const renderedSpriteSheet = await renderSpriteSheetToString( | ||
renderedString, | ||
cache, | ||
); | ||
|
||
expect(renderedSpriteSheet).toMatchInlineSnapshot( | ||
`"<svg><use xlink:href=\\"#1\\"></use></svg><svg id=\\"__SVG_SPRITE_SHEET__\\" style=\\"display:none\\"><symbol id=\\"1\\" xmlns=\\"http://www.w3.org/2000/svg\\" viewBox=\\"0 0 24 24\\"><path d=\\"M0 0h24v24H0z\\" fill=\\"none\\"/></symbol></svg>"`, | ||
); | ||
}); |