@@ -276,4 +276,58 @@ describe('useWizard', () => {
276276 expect ( result . current . isFirstStep ) . toBe ( false ) ;
277277 expect ( result . current . isLastStep ) . toBe ( true ) ;
278278 } ) ;
279+
280+ describe ( 'onStepChange()' , ( ) => {
281+ const renderUseWizardHook = (
282+ onStepChange : ( index : number ) => void ,
283+ startIndex = 0 ,
284+ ) => {
285+ return renderHook ( ( ) => useWizard ( ) , {
286+ initialProps : {
287+ startIndex,
288+ onStepChange,
289+ } ,
290+ wrapper : ( { children, startIndex, onStepChange } ) => (
291+ < Wizard startIndex = { startIndex } onStepChange = { onStepChange } >
292+ < p > step 1 { children } </ p >
293+ < p > step 2 { children } </ p >
294+ < p > step 3 { children } </ p >
295+ </ Wizard >
296+ ) ,
297+ } ) ;
298+ } ;
299+
300+ test ( 'should invoke onStepChange when nextStep is called' , async ( ) => {
301+ const onStepChange = jest . fn ( ) ;
302+ const { result, waitForNextUpdate } = renderUseWizardHook ( onStepChange ) ;
303+
304+ result . current . nextStep ( ) ;
305+
306+ await waitForNextUpdate ( ) ;
307+
308+ expect ( onStepChange ) . toHaveBeenCalledWith ( 1 ) ;
309+ } ) ;
310+
311+ test ( 'should invoke onStepChange when previousStep is called' , async ( ) => {
312+ const onStepChange = jest . fn ( ) ;
313+ const { result } = renderUseWizardHook ( onStepChange , 1 ) ;
314+
315+ act ( ( ) => {
316+ result . current . previousStep ( ) ;
317+ } ) ;
318+
319+ expect ( onStepChange ) . toHaveBeenCalledWith ( 0 ) ;
320+ } ) ;
321+
322+ test ( 'should invoke onStepChange when goToStep is called' , async ( ) => {
323+ const onStepChange = jest . fn ( ) ;
324+ const { result } = renderUseWizardHook ( onStepChange ) ;
325+
326+ act ( ( ) => {
327+ result . current . goToStep ( 1 ) ;
328+ } ) ;
329+
330+ expect ( onStepChange ) . toHaveBeenCalledWith ( 1 ) ;
331+ } ) ;
332+ } ) ;
279333} ) ;
0 commit comments