Skip to content

Commit 3a9ccd4

Browse files
committed
fix: step index for no attached handler
1 parent 2435810 commit 3a9ccd4

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

src/wizard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

test/useWizard.test.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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 }) => {

0 commit comments

Comments
 (0)