Skip to content

Commit c9bba3d

Browse files
committed
test: add extra goToStep test case
1 parent 80a54ad commit c9bba3d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/wizard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ const Wizard: React.FC<WizardProps> = React.memo(
3333
stepIndex > 0 &&
3434
stepIndex < React.Children.toArray(children).length
3535
) {
36+
setActiveStep(stepIndex);
37+
} else {
3638
if (__DEV__) {
3739
logger.log(
3840
'warn',
@@ -42,7 +44,6 @@ const Wizard: React.FC<WizardProps> = React.memo(
4244
].join(''),
4345
);
4446
}
45-
setActiveStep(stepIndex);
4647
}
4748
});
4849

test/useWizard.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,21 @@ describe('useWizard', () => {
122122
expect(result.current.isLastStep).toBe(true);
123123
});
124124

125+
test('should go to given step index and not invoke `handleStep` handler', async () => {
126+
const handler = jest.fn();
127+
const { result } = renderUseWizardHook();
128+
129+
act(() => {
130+
result.current.handleStep(handler);
131+
result.current.goToStep(1);
132+
});
133+
134+
expect(handler).not.toBeCalled();
135+
expect(result.current.activeStep).toBe(1);
136+
expect(result.current.isFirstStep).toBe(false);
137+
expect(result.current.isLastStep).toBe(true);
138+
});
139+
125140
test('should not go to given step index when out of boundary', async () => {
126141
const { result } = renderUseWizardHook();
127142

0 commit comments

Comments
 (0)