File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ const Wizard: React.FC<WizardProps> = React.memo(
4646 throw error ;
4747 }
4848 } else {
49- goToNextStep . current ( ) ;
49+ goToNextStep . current ( stepIndex ) ;
5050 }
5151 } ) ;
5252
Original file line number Diff line number Diff line change @@ -114,6 +114,36 @@ describe('useWizard', () => {
114114 } ) ;
115115 } ) ;
116116
117+ test ( 'should go to passed step index on next step with handler' , ( ) => {
118+ const callback = jest . fn ( ) ;
119+
120+ const { result } = renderHook ( ( ) => useWizard ( ) , {
121+ wrapper : ( { children } : { children : React . ReactNode } ) => {
122+ return < Wizard > { children } </ Wizard > ;
123+ } ,
124+ initialProps : {
125+ children : (
126+ < >
127+ < p > step 1</ p >
128+ < p > step 2</ p >
129+ < p > step 3</ p >
130+ </ >
131+ ) ,
132+ } ,
133+ } ) ;
134+
135+ act ( ( ) => {
136+ result . current . handleStep ( callback ) ;
137+ } ) ;
138+ // Wait for an element to appear
139+ waitFor ( ( ) => {
140+ result . current . nextStep ( 2 ) ;
141+ expect ( result . current . isFirstStep ) . toBe ( false ) ;
142+ expect ( result . current . isLastStep ) . toBe ( true ) ;
143+ expect ( callback ) . toBeCalled ( ) ;
144+ } ) ;
145+ } ) ;
146+
117147 test ( 'should go to passed step index on previous step' , ( ) => {
118148 const { result } = renderHook ( ( ) => useWizard ( ) , {
119149 wrapper : ( { children } : { children : React . ReactNode } ) => {
You can’t perform that action at this time.
0 commit comments