1- /* eslint-disable jsx-a11y/click-events-have-key-events */
2- /* eslint-disable jsx-a11y/no-static-element-interactions */
31import React from 'react' ;
42import { render , screen } from '@testing-library/react' ;
53import userEvent from '@testing-library/user-event' ;
64import { IntlProvider } from 'react-intl' ;
75import ChipCarousel from '.' ;
6+ import Chip from '../Chip' ;
87
9- const items = [
10- < div onClick = { jest . fn ( ) } data-testid = "chip" > Item 1</ div > ,
11- < div onClick = { jest . fn ( ) } data-testid = "chip" > Item 2</ div > ,
12- < div onClick = { jest . fn ( ) } data-testid = "chip" > Item 3</ div > ,
13- < div onClick = { jest . fn ( ) } data-testid = "chip" /> ,
14- ] ;
8+ const items = Array . from ( { length : 4 } , ( _ , i ) => (
9+ < Chip onClick = { jest . fn ( ) } >
10+ { `Item ${ i + 1 } ` }
11+ </ Chip >
12+ ) ) ;
1513
1614const ariaLabel = 'Test aria label' ;
1715function TestingChipCarousel ( props ) {
@@ -29,9 +27,9 @@ describe('<ChipCarousel />', () => {
2927 const carousel = screen . getByTestId ( 'chip-carousel' ) ;
3028 expect ( carousel ) . toBeTruthy ( ) ;
3129
32- const chipItems = screen . queryAllByTestId ( 'chip ') ;
33- expect ( chipItems ) . toHaveLength ( items . length - 1 ) ;
34- for ( let i = 0 ; i < chipItems . length - 1 ; i ++ ) {
30+ const chipItems = screen . queryAllByRole ( 'button ') ;
31+ expect ( chipItems ) . toHaveLength ( items . length ) ;
32+ for ( let i = 0 ; i < chipItems . length ; i ++ ) {
3533 expect ( chipItems [ i ] . textContent ) . toBe ( items [ i ] . props . children ) ;
3634 }
3735 } ) ;
0 commit comments