@@ -3,7 +3,7 @@ import {render} from '@testing-library/react'
33import '@testing-library/jest-dom'
44import { axe , toHaveNoViolations } from 'jest-axe'
55
6- import { Image , ImageBorderRadiusOptions } from './'
6+ import { Image , ImageAspectRatio , ImageBorderRadiusOptions } from './'
77
88expect . extend ( toHaveNoViolations )
99
@@ -17,7 +17,7 @@ describe('Image', () => {
1717 expect ( results ) . toHaveNoViolations ( )
1818 } )
1919
20- it ( 'should render an img element' , async ( ) => {
20+ it ( 'should render an img element' , ( ) => {
2121 const { getByAltText} = render (
2222 < Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" /> ,
2323 )
@@ -28,7 +28,7 @@ describe('Image', () => {
2828 expect ( imageElement . tagName ) . toBe ( 'IMG' )
2929 } )
3030
31- it ( 'should apply animation styles when `animate` is provided' , async ( ) => {
31+ it ( 'should apply animation styles when `animate` is provided' , ( ) => {
3232 const { getByRole} = render (
3333 < Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" animate = "scale-in" /> ,
3434 )
@@ -39,7 +39,7 @@ describe('Image', () => {
3939 expect ( imageElement ) . toHaveClass ( 'Animation--scale-in' )
4040 } )
4141
42- it ( 'should forward the `className` prop to the image' , async ( ) => {
42+ it ( 'should forward the `className` prop to the image' , ( ) => {
4343 const testClass = 'test'
4444
4545 const { getByRole} = render (
@@ -53,7 +53,7 @@ describe('Image', () => {
5353 expect ( getByRole ( 'img' ) ) . toHaveClass ( testClass )
5454 } )
5555
56- it ( 'should forward the `style` prop to the image' , async ( ) => {
56+ it ( 'should forward the `style` prop to the image' , ( ) => {
5757 const { getByRole} = render (
5858 < Image
5959 src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png"
@@ -65,18 +65,36 @@ describe('Image', () => {
6565 expect ( getByRole ( 'img' ) ) . toHaveStyle ( { background : 'red' } )
6666 } )
6767
68- it ( 'should forward the `alt` prop to the image' , async ( ) => {
68+ it ( 'should forward the `alt` prop to the image' , ( ) => {
6969 const { getByAltText} = render (
7070 < Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" /> ,
7171 )
7272
7373 expect ( getByAltText ( 'alternative text' ) ) . toBeInTheDocument ( )
7474 } )
7575
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 => {
7777 const { getByRole} = render (
7878 < Image src = "https://via.placeholder.com/600x400/d3d9df/d3d9df.png" alt = "alternative text" borderRadius = { size } /> ,
7979 )
8080 expect ( getByRole ( 'img' ) ) . toHaveClass ( `Image--borderRadius-${ size } ` )
8181 } )
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+ } )
82100} )
0 commit comments