@@ -3,7 +3,7 @@ import {render} from '@testing-library/react'
3
3
import '@testing-library/jest-dom'
4
4
import { axe , toHaveNoViolations } from 'jest-axe'
5
5
6
- import { Image , ImageBorderRadiusOptions } from './'
6
+ import { Image , ImageAspectRatio , ImageBorderRadiusOptions } from './'
7
7
8
8
expect . extend ( toHaveNoViolations )
9
9
@@ -17,7 +17,7 @@ describe('Image', () => {
17
17
expect ( results ) . toHaveNoViolations ( )
18
18
} )
19
19
20
- it ( 'should render an img element' , async ( ) => {
20
+ it ( 'should render an img element' , ( ) => {
21
21
const { getByAltText} = render (
22
22
< Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" /> ,
23
23
)
@@ -28,7 +28,7 @@ describe('Image', () => {
28
28
expect ( imageElement . tagName ) . toBe ( 'IMG' )
29
29
} )
30
30
31
- it ( 'should apply animation styles when `animate` is provided' , async ( ) => {
31
+ it ( 'should apply animation styles when `animate` is provided' , ( ) => {
32
32
const { getByRole} = render (
33
33
< Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" animate = "scale-in" /> ,
34
34
)
@@ -39,7 +39,7 @@ describe('Image', () => {
39
39
expect ( imageElement ) . toHaveClass ( 'Animation--scale-in' )
40
40
} )
41
41
42
- it ( 'should forward the `className` prop to the image' , async ( ) => {
42
+ it ( 'should forward the `className` prop to the image' , ( ) => {
43
43
const testClass = 'test'
44
44
45
45
const { getByRole} = render (
@@ -53,7 +53,7 @@ describe('Image', () => {
53
53
expect ( getByRole ( 'img' ) ) . toHaveClass ( testClass )
54
54
} )
55
55
56
- it ( 'should forward the `style` prop to the image' , async ( ) => {
56
+ it ( 'should forward the `style` prop to the image' , ( ) => {
57
57
const { getByRole} = render (
58
58
< Image
59
59
src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png"
@@ -65,18 +65,36 @@ describe('Image', () => {
65
65
expect ( getByRole ( 'img' ) ) . toHaveStyle ( { background : 'red' } )
66
66
} )
67
67
68
- it ( 'should forward the `alt` prop to the image' , async ( ) => {
68
+ it ( 'should forward the `alt` prop to the image' , ( ) => {
69
69
const { getByAltText} = render (
70
70
< Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" /> ,
71
71
)
72
72
73
73
expect ( getByAltText ( 'alternative text' ) ) . toBeInTheDocument ( )
74
74
} )
75
75
76
- it . each ( ImageBorderRadiusOptions ) ( 'should add the appropriate class when `borderRadius="%s"`' , async size => {
76
+ it . each ( ImageBorderRadiusOptions ) ( 'should add the appropriate class when `borderRadius="%s"`' , size => {
77
77
const { getByRole} = render (
78
78
< Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" borderRadius = { size } /> ,
79
79
)
80
80
expect ( getByRole ( 'img' ) ) . toHaveClass ( `Image--borderRadius-${ size } ` )
81
81
} )
82
+
83
+ it . each < { aspectRatio : ImageAspectRatio ; classSuffix : string } > ( [
84
+ { aspectRatio : '1:1' , classSuffix : '1-1' } ,
85
+ { aspectRatio : '16:9' , classSuffix : '16-9' } ,
86
+ { aspectRatio : '16:10' , classSuffix : '16-10' } ,
87
+ { aspectRatio : '4:3' , classSuffix : '4-3' } ,
88
+ { aspectRatio : 'custom' , classSuffix : 'custom' } ,
89
+ ] ) ( 'should add the appropriate class when `aspectRatio="$aspectRatio"`' , ( { aspectRatio, classSuffix} ) => {
90
+ const { getByRole} = render (
91
+ < Image
92
+ src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png"
93
+ alt = "alternative text"
94
+ aspectRatio = { aspectRatio }
95
+ /> ,
96
+ )
97
+
98
+ expect ( getByRole ( 'img' ) ) . toHaveClass ( `Image--aspectRatio-${ classSuffix } ` )
99
+ } )
82
100
} )
0 commit comments