@@ -5,23 +5,27 @@ import { cleanup, render, fireEvent, waitFor } from '@testing-library/react';
55
66import '@testing-library/jest-dom' ;
77
8- import Image from '../Image' ;
8+ import ImageComponent from '../Image' ;
99
1010const mockImageAssets = 'https://placeimg.com/640/480/any' ;
1111
1212afterEach ( cleanup ) ; // eslint-disable-line
1313
1414describe ( 'Image' , ( ) => {
1515 it ( 'should render component with default props' , ( ) => {
16- const tree = renderer . create ( < Image images = { mockImageAssets } /> ) . toJSON ( ) ;
16+ const tree = renderer
17+ . create ( < ImageComponent images = { mockImageAssets } /> )
18+ . toJSON ( ) ;
1719 expect ( tree ) . toMatchSnapshot ( ) ;
1820 } ) ;
1921
2022 describe ( 'it should prevent unsafe image uri protocols in the rendered image src' , ( ) => {
2123 it ( 'should prevent javascript protocol in image src' , ( ) => {
2224 // eslint-disable-next-line no-script-url
2325 const xssJavascriptUri = 'javascript:alert("p0wn3d")' ;
24- const { getByTestId } = render ( < Image image_url = { xssJavascriptUri } /> ) ;
26+ const { getByTestId } = render (
27+ < ImageComponent image_url = { xssJavascriptUri } /> ,
28+ ) ;
2529 expect ( getByTestId ( 'image-test' ) ) . not . toHaveAttribute (
2630 'src' ,
2731 xssJavascriptUri ,
@@ -30,28 +34,30 @@ describe('Image', () => {
3034 it ( 'should prevent javascript protocol in thumbnail src' , ( ) => {
3135 // eslint-disable-next-line no-script-url
3236 const xssJavascriptUri = 'javascript:alert("p0wn3d")' ;
33- const { getByTestId } = render ( < Image thumb_url = { xssJavascriptUri } /> ) ;
37+ const { getByTestId } = render (
38+ < ImageComponent thumb_url = { xssJavascriptUri } /> ,
39+ ) ;
3440 expect ( getByTestId ( 'image-test' ) ) . not . toHaveAttribute (
3541 'src' ,
3642 xssJavascriptUri ,
3743 ) ;
3844 } ) ;
3945 it ( 'should prevent dataUris in image src' , ( ) => {
4046 const xssDataUri = 'data:image/svg+xml;base64,DANGEROUSENCODEDSVG' ;
41- const { getByTestId } = render ( < Image image_url = { xssDataUri } /> ) ;
47+ const { getByTestId } = render ( < ImageComponent image_url = { xssDataUri } /> ) ;
4248 expect ( getByTestId ( 'image-test' ) ) . not . toHaveAttribute ( 'src' , xssDataUri ) ;
4349 } ) ;
4450 it ( 'should prevent dataUris in thumb src' , ( ) => {
4551 const xssDataUri = 'data:image/svg+xml;base64,DANGEROUSENCODEDSVG' ;
46- const { getByTestId } = render ( < Image thumb_url = { xssDataUri } /> ) ;
52+ const { getByTestId } = render ( < ImageComponent thumb_url = { xssDataUri } /> ) ;
4753 expect ( getByTestId ( 'image-test' ) ) . not . toHaveAttribute ( 'src' , xssDataUri ) ;
4854 } ) ;
4955 } ) ;
5056
5157 it ( 'should open modal on image click' , async ( ) => {
5258 jest . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => null ) ;
5359 const { getByTestId, getByTitle } = render (
54- < Image images = { mockImageAssets } /> ,
60+ < ImageComponent images = { mockImageAssets } /> ,
5561 ) ;
5662 fireEvent . click ( getByTestId ( 'image-test' ) ) ;
5763
0 commit comments