Skip to content

Commit

Permalink
fix: types for onNext callback
Browse files Browse the repository at this point in the history
  • Loading branch information
willmendesneto committed Oct 29, 2021
1 parent 3fe39cc commit 45e060d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][]

### Fixed

- Fixing types for `onNext` to cover the callback scenario

## [1.0.1][] - 2021-10-29

### Updated
Expand Down Expand Up @@ -43,7 +47,5 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

[unreleased]: https://github.com/willmendesneto/react-sweet-wizard/compare/v1.0.0...HEAD
[1.0.0]: https://github.com/willmendesneto/react-sweet-wizard/tree/v1.0.0


[Unreleased]: https://github.com/willmendesneto/react-sweet-wizard/compare/v1.0.1...HEAD
[1.0.1]: https://github.com/willmendesneto/react-sweet-wizard/tree/v1.0.1
[unreleased]: https://github.com/willmendesneto/react-sweet-wizard/compare/v1.0.1...HEAD
[1.0.1]: https://github.com/willmendesneto/react-sweet-wizard/tree/v1.0.1
16 changes: 16 additions & 0 deletions src/useWizard.test.tsx
Expand Up @@ -29,6 +29,8 @@ const renderUseWizardHook = (initialStartIndex = 0) =>
});

describe('useWizard hook', () => {
afterEach(jest.resetAllMocks);

it('should throw an error if hooks is NOT using wizard provider as wrapper', () => {
const { result } = renderHook(() => useWizardContext(), {
wrapper: props => <div {...props} />,
Expand Down Expand Up @@ -90,6 +92,20 @@ describe('useWizard hook', () => {
});
});

it('call should be called if passed on `onNext`', async () => {
const { result, waitFor } = renderUseWizardHook();
expect(result.current).toBeDefined();

const handleNext = jest.fn();
act(() => {
result.current.onNext(handleNext);
});

await waitFor(() => {
expect(result.current.activeStepIndex).toBe(1);
});
});

it('should not break if user goes above or below available steps', () => {
const { result } = renderUseWizardHook();
expect(result.current).toBeDefined();
Expand Down
2 changes: 1 addition & 1 deletion src/useWizard.tsx
Expand Up @@ -33,7 +33,7 @@ interface WizardStepperContextProps<T = DefaultWizardStepProps> {
readonly isFirstStep: boolean;
readonly isLastStep: boolean;
goTo: (id: number | string) => void;
onNext: () => void;
onNext: (cb?: () => void) => void;
getActiveStep: () => T;
onPrevious: () => void;
setSteps: (steps: T[] | T) => void;
Expand Down

0 comments on commit 45e060d

Please sign in to comment.