Skip to content

Commit 77b847c

Browse files
committed
test: add goToStep tests
1 parent 3544eef commit 77b847c

File tree

1 file changed

+13
-35
lines changed

1 file changed

+13
-35
lines changed

test/useWizard.test.tsx

Lines changed: 13 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -99,60 +99,38 @@ describe('useWizard', () => {
9999
expect(result.current.isLastStep).toBe(true);
100100
});
101101

102-
test('should go to passed step index on next step', async () => {
103-
const { result, waitForNextUpdate } = renderHook(() => useWizard(), {
104-
wrapper: ({ children }) => (
105-
<Wizard>
106-
<p>step 1 {children}</p>
107-
<p>step 2 {children}</p>
108-
<p>step 3 {children}</p>
109-
</Wizard>
110-
),
111-
});
102+
test('should not go to previous step if first step', async () => {
103+
const { result } = renderUseWizardHook();
112104

113105
act(() => {
114-
result.current.nextStep(2);
106+
result.current.previousStep();
115107
});
116108

117-
await waitForNextUpdate();
118-
119-
expect(result.current.isFirstStep).toBe(false);
120-
expect(result.current.isLastStep).toBe(true);
109+
// Wait for an element to appear
110+
expect(result.current.activeStep).toBe(0);
121111
});
122112

123-
test('should go to passed step index on next step with handler', async () => {
124-
const callback = jest.fn();
125-
126-
const { result, waitForNextUpdate } = renderHook(() => useWizard(), {
127-
wrapper: ({ children }) => (
128-
<Wizard>
129-
<p>step 1 {children}</p>
130-
<p>step 2 {children}</p>
131-
<p>step 3 {children}</p>
132-
</Wizard>
133-
),
134-
});
113+
test('should go to given step index', async () => {
114+
const { result } = renderUseWizardHook();
135115

136116
act(() => {
137-
result.current.handleStep(callback);
138-
result.current.nextStep(2);
117+
result.current.goToStep(1);
139118
});
140119

141-
await waitForNextUpdate();
142-
120+
expect(result.current.activeStep).toBe(1);
143121
expect(result.current.isFirstStep).toBe(false);
144122
expect(result.current.isLastStep).toBe(true);
145-
expect(callback).toBeCalled();
146123
});
147124

148-
test('should not go to previous step if first step', async () => {
125+
test('should not go to given step index when out of boundary', async () => {
149126
const { result } = renderUseWizardHook();
150127

151128
act(() => {
152-
result.current.previousStep();
129+
result.current.goToStep(2);
153130
});
154131

155-
// Wait for an element to appear
156132
expect(result.current.activeStep).toBe(0);
133+
expect(result.current.isFirstStep).toBe(true);
134+
expect(result.current.isLastStep).toBe(false);
157135
});
158136
});

0 commit comments

Comments
 (0)