2
2
3
3
const img = require ( '../../../../lib/js/img-helper' ) ;
4
4
5
- const xlinkData = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><use xlink:href="../../../../__mocks__/img/test.svg#circle"></use></svg></body></html>` ;
6
- const hrefData = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><use href="../../../../__mocks__/img/test.svg#circle"></use></svg></body></html>` ;
7
- const noIdData = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><use href="../../../../__mocks__/img/test.svg"></use></svg></body></html>` ;
8
- const svgResultWithId = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><svg id="circle"><circle xmlns="http://www.w3.org/2000/svg" cx="50" cy="50" r="25" stroke="#000" stroke-width="2" fill="red"></circle></svg></svg></body></html>` ;
9
- const svgResultWithoutId = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><svg id="circle"><circle xmlns="http://www.w3.org/2000/svg" cx="50" cy="50" r="25" stroke="#000" stroke-width="2" fill="red"></circle></svg><svg id="square"><path fill="#00f" stroke="#000" d="M0 0h100v100H0z"></path></svg></svg></svg></body></html>` ;
5
+ const xlinkData = `<html><head></head><body><svg><use xlink:href="../../../../__mocks__/img/test.svg#circle"></use></svg></body></html>` ;
6
+ const hrefData = `<html><head></head><body><svg><use href="../../../../__mocks__/img/test.svg#circle"></use></svg></body></html>` ;
7
+ const noIdData = `<html><head></head><body><svg><use href="../../../../__mocks__/img/test.svg"></use></svg></body></html>` ;
8
+ const svgResultWithId = `<html><head></head><body><svg><svg id="circle"><circle xmlns="http://www.w3.org/2000/svg" cx="50" cy="50" r="25" stroke="#000" stroke-width="2" fill="red"></circle></svg></svg></body></html>` ;
9
+ const svgResultWithoutId = `<html><head></head><body><svg><svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><svg id="circle"><circle xmlns="http://www.w3.org/2000/svg" cx="50" cy="50" r="25" stroke="#000" stroke-width="2" fill="red"></circle></svg><svg id="square"><path fill="#00f" stroke="#000" d="M0 0h100v100H0z"></path></svg></svg></svg></body></html>` ;
10
10
11
11
const pngData = `<html><head></head><body><img src="../../../../__mocks__/img/test.png"></body></html>` ;
12
12
const pngResult = `<html><head></head><body><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAEElEQVR42gEFAPr/AAAAAP8BBAEAZ5TsRgAAAABJRU5ErkJggg=="></body></html>` ;
@@ -16,9 +16,10 @@ const svgResult = `<html><head></head><body><img src="data:image/svg+xml;base64,
16
16
const httpData = `<html><head></head><body><img src="http://www.example.com/test.png"></body></html>` ;
17
17
const httpsData = `<html><head></head><body><img src="https://www.example.com/test.png"></body></html>` ;
18
18
const protocolData = `<html><head></head><body><img src="//www.example.com/test.png"></body></html>` ;
19
+ const internalXlinkData = `<html><head></head><body><svg><use xlink:href="#circle"></use></svg></body></html>` ;
19
20
20
21
const noImgData = `<html><head></head><body><img src="../../../../__mocks__/img/missing.png"></body></html>` ;
21
- const noUseData = `<html><head></head><body><svg width="24" height="24" role="img" aria-label="" focusable="false" ><use href="../../../../__mocks__/img/missing.svg#circle"></use></svg></body></html>` ;
22
+ const noUseData = `<html><head></head><body><svg><use href="../../../../__mocks__/img/missing.svg#circle"></use></svg></body></html>` ;
22
23
23
24
console . log = jest . fn ( ) ; // silence log output from module under test
24
25
@@ -81,6 +82,12 @@ describe('Image helper', () => {
81
82
expect ( result ) . toMatch ( svgResultWithoutId ) ;
82
83
} ) ;
83
84
85
+ test ( 'ignore internal links by hash' , async ( ) => {
86
+ expect . assertions ( 1 ) ;
87
+ let result = await img ( internalXlinkData , __dirname ) ;
88
+ expect ( result ) . toMatch ( internalXlinkData ) ;
89
+ } ) ;
90
+
84
91
test ( 'fail: svg doesn\'t exist' , async ( ) => {
85
92
expect . assertions ( 1 ) ;
86
93
await expect ( img ( noUseData , __dirname ) )
0 commit comments