1+ import "@testing-library/jest-dom" ;
2+ import { render } from "@testing-library/react" ;
3+ import userEvent , { UserEvent } from "@testing-library/user-event" ;
14import { createElement } from "react" ;
2- import { mount , render } from "enzyme " ;
5+ import { ModalProps } from "react-overlays/esm/Modal " ;
36import { Image , ImageProps } from "../Image/Image" ;
47import { Lightbox } from "../Lightbox" ;
5- import { ModalProps } from "react-overlays/esm/Modal" ;
68
79jest . mock ( "../../assets/ic24-close.svg" , ( ) => "close-button-icon-svg" ) ;
810
@@ -70,33 +72,38 @@ const iconProps: ImageProps = {
7072
7173describe ( "Image" , ( ) => {
7274 it ( "renders the structure with an image" , ( ) => {
73- expect ( render ( < Image { ...imageProps } /> ) ) . toMatchSnapshot ( ) ;
75+ const image = render ( < Image { ...imageProps } /> ) ;
76+ expect ( image . asFragment ( ) ) . toMatchSnapshot ( ) ;
7477 } ) ;
7578
7679 it ( "renders the structure with an image and percentage dimensions" , ( ) => {
77- expect (
78- render ( < Image { ...imageProps } height = { 100 } width = { 100 } heightUnit = "auto" widthUnit = "percentage" /> )
79- ) . toMatchSnapshot ( ) ;
80+ const image = render (
81+ < Image { ...imageProps } height = { 100 } width = { 100 } heightUnit = "auto" widthUnit = "percentage" />
82+ ) ;
83+ expect ( image . asFragment ( ) ) . toMatchSnapshot ( ) ;
8084 } ) ;
8185
8286 it ( "renders the structure with a glyph icon" , ( ) => {
83- expect ( render ( < Image { ...glyphiconProps } /> ) ) . toMatchSnapshot ( ) ;
87+ const image = render ( < Image { ...glyphiconProps } /> ) ;
88+ expect ( image . asFragment ( ) ) . toMatchSnapshot ( ) ;
8489 } ) ;
8590
8691 it ( "renders the structure with an icon" , ( ) => {
87- expect ( render ( < Image { ...iconProps } /> ) ) . toMatchSnapshot ( ) ;
92+ const image = render ( < Image { ...iconProps } /> ) ;
93+ expect ( image . asFragment ( ) ) . toMatchSnapshot ( ) ;
8894 } ) ;
8995
9096 it ( "renders the structure as a background image" , ( ) => {
91- expect (
92- render ( < Image { ...imageProps } renderAsBackground backgroundImageContent = { < div > Image content</ div > } /> )
93- ) . toMatchSnapshot ( ) ;
97+ const image = render (
98+ < Image { ...imageProps } renderAsBackground backgroundImageContent = { < div > Image content</ div > } />
99+ ) ;
100+ expect ( image . asFragment ( ) ) . toMatchSnapshot ( ) ;
94101 } ) ;
95102
96103 describe ( "when the onClickType is action" , ( ) => {
97104 it ( "calls the onClick when clicking on an image" , ( ) => {
98105 const onClickMock = jest . fn ( ) ;
99- const imageRender = mount ( < Image { ...imageProps } onClick = { onClickMock } onClickType = "action" /> ) ;
106+ const imageRender = render ( < Image { ...imageProps } onClick = { onClickMock } onClickType = "action" /> ) ;
100107
101108 const image = imageRender . find ( "img" ) ;
102109 expect ( image ) . toHaveLength ( 1 ) ;
@@ -107,7 +114,7 @@ describe("Image", () => {
107114
108115 it ( "has tabindex if there is an action with OnClick" , ( ) => {
109116 const onClickMock = jest . fn ( ) ;
110- const imageRender = mount (
117+ const imageRender = render (
111118 < Image { ...imageProps } onClick = { onClickMock } onClickType = "action" tabIndex = { 1 } />
112119 ) ;
113120 const image = imageRender . find ( "img" ) ;
@@ -117,15 +124,15 @@ describe("Image", () => {
117124 } ) ;
118125
119126 it ( "has no tabindex if there is no action with OnClick" , ( ) => {
120- const imageRender = mount ( < Image { ...imageProps } /> ) ;
127+ const imageRender = render ( < Image { ...imageProps } /> ) ;
121128 const image = imageRender . find ( "img" ) ;
122129
123130 expect ( image . prop ( "tabIndex" ) ) . toBeUndefined ( ) ;
124131 } ) ;
125132
126133 it ( "calls the onClick when clicking on a glyph icon" , ( ) => {
127134 const onClickMock = jest . fn ( ) ;
128- const imageRender = mount ( < Image { ...glyphiconProps } onClick = { onClickMock } onClickType = "action" /> ) ;
135+ const imageRender = render ( < Image { ...glyphiconProps } onClick = { onClickMock } onClickType = "action" /> ) ;
129136
130137 const glyphicon = imageRender . find ( "span" ) ;
131138 expect ( glyphicon ) . toHaveLength ( 1 ) ;
@@ -136,7 +143,7 @@ describe("Image", () => {
136143
137144 it ( "calls the onClick when clicking on an icon" , ( ) => {
138145 const onClickMock = jest . fn ( ) ;
139- const imageRender = mount ( < Image { ...iconProps } onClick = { onClickMock } onClickType = "action" /> ) ;
146+ const imageRender = render ( < Image { ...iconProps } onClick = { onClickMock } onClickType = "action" /> ) ;
140147
141148 const glyphicon = imageRender . find ( "span" ) ;
142149 expect ( glyphicon ) . toHaveLength ( 1 ) ;
@@ -148,7 +155,7 @@ describe("Image", () => {
148155
149156 describe ( "when the onClickType is enlarge" , ( ) => {
150157 it ( "shows a lightbox when the user clicks on the image" , ( ) => {
151- const imageRender = mount ( < Image { ...imageProps } onClickType = "enlarge" /> ) ;
158+ const imageRender = render ( < Image { ...imageProps } onClickType = "enlarge" /> ) ;
152159 expect ( imageRender . find ( Lightbox ) ) . toHaveLength ( 0 ) ;
153160
154161 const image = imageRender . find ( "img" ) ;
@@ -159,7 +166,7 @@ describe("Image", () => {
159166 } ) ;
160167
161168 it ( "closes the lightbox when the user clicks on the close button after opening it" , ( ) => {
162- const imageRender = mount ( < Image { ...imageProps } onClickType = "enlarge" /> ) ;
169+ const imageRender = render ( < Image { ...imageProps } onClickType = "enlarge" /> ) ;
163170
164171 const image = imageRender . find ( "img" ) ;
165172 expect ( image ) . toHaveLength ( 1 ) ;
@@ -178,7 +185,7 @@ describe("Image", () => {
178185 it ( "does not trigger on clicks from containers if clicked on the image" , ( ) => {
179186 const onClickOuterMock = jest . fn ( ) ;
180187 const onClickImageMock = jest . fn ( ) ;
181- const imageRender = mount (
188+ const imageRender = render (
182189 < div onClick = { onClickOuterMock } >
183190 < Image { ...imageProps } onClickType = "action" onClick = { onClickImageMock } />
184191 </ div >
@@ -194,20 +201,20 @@ describe("Image", () => {
194201
195202 describe ( "when there is an accessibility alt text" , ( ) => {
196203 it ( "is set properly on an image" , ( ) => {
197- const imageRender = mount ( < Image { ...imageProps } altText = "this is an awesome image" /> ) ;
204+ const imageRender = render ( < Image { ...imageProps } altText = "this is an awesome image" /> ) ;
198205 const image = imageRender . find ( "img" ) ;
199206 expect ( image . prop ( "alt" ) ) . toBe ( "this is an awesome image" ) ;
200207 } ) ;
201208
202209 it ( "is set properly on a glyphicon" , ( ) => {
203- const imageRender = mount ( < Image { ...glyphiconProps } altText = "this is an awesome glyphicon" /> ) ;
210+ const imageRender = render ( < Image { ...glyphiconProps } altText = "this is an awesome glyphicon" /> ) ;
204211 const image = imageRender . find ( "span" ) ;
205212 expect ( image . prop ( "aria-label" ) ) . toBe ( "this is an awesome glyphicon" ) ;
206213 expect ( image . prop ( "role" ) ) . toBe ( "img" ) ;
207214 } ) ;
208215
209216 it ( "is set properly on an icon" , ( ) => {
210- const imageRender = mount ( < Image { ...iconProps } altText = "this is an awesome icon" /> ) ;
217+ const imageRender = render ( < Image { ...iconProps } altText = "this is an awesome icon" /> ) ;
211218 const image = imageRender . find ( "span" ) ;
212219 expect ( image . prop ( "aria-label" ) ) . toBe ( "this is an awesome icon" ) ;
213220 expect ( image . prop ( "role" ) ) . toBe ( "img" ) ;
@@ -216,20 +223,20 @@ describe("Image", () => {
216223
217224 describe ( "when there is no accessibility alt text" , ( ) => {
218225 it ( "nothing is set on an image" , ( ) => {
219- const imageRender = mount ( < Image { ...imageProps } /> ) ;
226+ const imageRender = render ( < Image { ...imageProps } /> ) ;
220227 const image = imageRender . find ( "img" ) ;
221228 expect ( image . prop ( "alt" ) ) . toBe ( undefined ) ;
222229 } ) ;
223230
224231 it ( "nothing is set on a glyphicon" , ( ) => {
225- const imageRender = mount ( < Image { ...glyphiconProps } /> ) ;
232+ const imageRender = render ( < Image { ...glyphiconProps } /> ) ;
226233 const image = imageRender . find ( "span" ) ;
227234 expect ( image ) . not . toHaveProperty ( "aria-label" ) ;
228235 expect ( image ) . not . toHaveProperty ( "role" ) ;
229236 } ) ;
230237
231238 it ( "nothing is set on an icon" , ( ) => {
232- const imageRender = mount ( < Image { ...iconProps } /> ) ;
239+ const imageRender = render ( < Image { ...iconProps } /> ) ;
233240 const image = imageRender . find ( "span" ) ;
234241 expect ( image ) . not . toHaveProperty ( "aria-label" ) ;
235242 expect ( image ) . not . toHaveProperty ( "role" ) ;
@@ -238,13 +245,13 @@ describe("Image", () => {
238245
239246 describe ( "when showing an image as a thumbnail" , ( ) => {
240247 it ( "includes the thumb=true URL param in the image" , ( ) => {
241- const imageRender = mount ( < Image { ...imageProps } displayAs = "thumbnail" /> ) ;
248+ const imageRender = render ( < Image { ...imageProps } displayAs = "thumbnail" /> ) ;
242249 const image = imageRender . find ( "img" ) ;
243250 expect ( image . prop ( "src" ) ) . toContain ( "thumb=true" ) ;
244251 } ) ;
245252
246253 it ( "does not include the thumb=true URL param in the lightbox image" , ( ) => {
247- const imageRender = mount ( < Image { ...imageProps } displayAs = "thumbnail" onClickType = "enlarge" /> ) ;
254+ const imageRender = render ( < Image { ...imageProps } displayAs = "thumbnail" onClickType = "enlarge" /> ) ;
248255
249256 const image = imageRender . find ( "img" ) ;
250257 expect ( image . prop ( "src" ) ) . toContain ( "thumb=true" ) ;
@@ -264,15 +271,15 @@ describe("Image", () => {
264271
265272 describe ( "when showing as a background image" , ( ) => {
266273 it ( "shows the content" , ( ) => {
267- const imageRender = mount (
274+ const imageRender = render (
268275 < Image { ...imageProps } renderAsBackground backgroundImageContent = { < div > Image content</ div > } />
269276 ) ;
270277 expect ( imageRender . text ( ) ) . toContain ( "Image content" ) ;
271278 } ) ;
272279
273280 it ( "properly handles on click event if configured by the user" , ( ) => {
274281 const onClickMock = jest . fn ( ) ;
275- const imageRender = mount (
282+ const imageRender = render (
276283 < Image
277284 { ...imageProps }
278285 renderAsBackground
0 commit comments