11import React from 'react' ;
2- import { render , fireEvent } from "@testing-library/react" ;
2+ import {
3+ render ,
4+ fireEvent ,
5+ queryByAttribute ,
6+ queryAllByAttribute
7+ } from "@testing-library/react" ;
38import { IStep } from '../stepper-component/types' ;
49import Stepper from "../stepper-component/stepperComponent" ;
510
11+ const getById = queryByAttribute . bind ( null , 'id' ) ;
12+ const getAllById = queryAllByAttribute . bind ( null , 'id' ) ;
613test ( "Stepper Component - Label and description" , async ( ) => {
714 const steps : IStep [ ] = [ {
815 label : 'Step 1' ,
916 description : 'Demo description' ,
1017 status : 'completed'
1118 } ]
12- const { findByTestId } = render ( < Stepper steps = { steps } /> )
13- const label = await findByTestId ( "stepper-label-0" ) ;
19+ const dom = render ( < Stepper steps = { steps } /> )
20+ const label = await getById ( dom . container , "stepper-label-0" ) ;
1421 expect ( label . innerHTML ) . toBe ( 'Step 1' ) ;
15- const description = await findByTestId ( "stepper-desc-0" ) ;
22+ const description = await getById ( dom . container , "stepper-desc-0" ) ;
1623 expect ( description . innerHTML ) . toBe ( 'Demo description' ) ;
1724} ) ;
1825
@@ -21,9 +28,10 @@ test("Stepper Component - No description", async () => {
2128 label : 'Step 1' ,
2229 status : 'completed'
2330 } ] ;
24- const { findByTestId } = render ( < Stepper steps = { steps } /> )
31+ const dom = render ( < Stepper steps = { steps } /> )
2532 try {
26- await findByTestId ( "stepper-desc-0" ) ;
33+ const val = await getById ( dom . container , "stepper-desc-0" ) ;
34+ if ( val === null ) throw Error ( ) ;
2735 } catch ( err ) {
2836 return ;
2937 }
@@ -38,8 +46,8 @@ test("Stepper Component - Number of steps", async () => {
3846 label : 'Step 2' ,
3947 status : 'visited'
4048 } ] ;
41- const { findAllByTestId } = render ( < Stepper steps = { steps } /> ) ;
42- const elements = await findAllByTestId ( "stepper-steps" ) ;
49+ const dom = render ( < Stepper steps = { steps } /> ) ;
50+ const elements = await getAllById ( dom . container , "stepper-steps" ) ;
4351 expect ( elements ?. length ) . toBe ( 2 ) ;
4452} )
4553
@@ -50,13 +58,13 @@ test("Stepper Component - On Click function", async () => {
5058 status : 'completed'
5159 } ] ;
5260 const onClick = jest . fn ( ) ;
53- const { findByTestId } = render (
61+ const dom = render (
5462 < Stepper
5563 steps = { steps }
5664 onStepClick = { onClick }
5765 />
5866 )
59- const bubble = await findByTestId ( "stepper-bubble" ) ;
67+ const bubble = await getById ( dom . container , "stepper-bubble" ) ;
6068 fireEvent . click ( bubble ) ;
6169 expect ( onClick ) . toBeCalled ( ) ;
6270} )
0 commit comments