File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed
Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ const Wizard: React.FC<WizardProps> = React.memo(
1111 const hasNextStep = React . useRef ( true ) ;
1212 const hasPreviousStep = React . useRef ( false ) ;
1313 const nextStepHandler = React . useRef < Handler > ( ( ) => { } ) ;
14- const stepCount = React . Children . count ( children ) ;
14+ const stepCount = React . Children . toArray ( children ) . length ;
1515
1616 hasNextStep . current = activeStep < stepCount - 1 ;
1717 hasPreviousStep . current = activeStep > 0 ;
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ const renderUseWizardHook = (initialStartIndex = 0) => {
1212 wrapper : ( { children, startIndex } ) => (
1313 < Wizard startIndex = { startIndex } >
1414 < p > step 1 { children } </ p >
15+ { false && < p > Optional step</ p > }
1516 < p > step 2 { children } </ p >
1617 </ Wizard >
1718 ) ,
@@ -37,6 +38,20 @@ describe('useWizard', () => {
3738 expect ( result . current . stepCount ) . toBe ( 2 ) ;
3839 } ) ;
3940
41+ test ( 'should set step count to one when using falsy step' , ( ) => {
42+ const { result } = renderHook ( ( ) => useWizard ( ) , {
43+ wrapper : ( { children } ) => (
44+ < Wizard >
45+ < p > step 1 { children } </ p >
46+ < p > step 2 { children } </ p >
47+ { false && < p > step 3 { children } </ p > }
48+ </ Wizard >
49+ ) ,
50+ } ) ;
51+
52+ expect ( result . current . stepCount ) . toBe ( 2 ) ;
53+ } ) ;
54+
4055 test ( 'should set active step to one' , ( ) => {
4156 const { result } = renderUseWizardHook ( 1 ) ;
4257
You can’t perform that action at this time.
0 commit comments