Skip to content

Commit

Permalink
fix: error throw tests;
Browse files Browse the repository at this point in the history
fix: better throw already `new Error`;
  • Loading branch information
xobotyi committed Oct 17, 2019
1 parent 8c7f7f5 commit 056875b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/__tests__/useMultiStateValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ describe('useMultiStateValidator', () => {
});

it('should throw if states is not an object', () => {
try {
expect(() => {
// @ts-ignore
getHook(defaultStatesValidator, 123);
} catch (err) {
expect(err).toBeDefined();
expect(err instanceof Error).toBe(true);
expect(err.message).toBe('states expected to be an object or array, got number');
}
const [, hook] = getHook(defaultStatesValidator, 123);

if (hook.result.error) {
throw hook.result.error;
}
}).toThrowError('states expected to be an object or array, got number');
});

it('first returned element should represent current validity state', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/useMultiStateValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function useMultiStateValidator<
S extends MultiStateValidatorStates = MultiStateValidatorStates
>(states: S, validator: MultiStateValidator<V, S>, initialValidity: V = [undefined] as V): UseValidatorReturn<V> {
if (typeof states !== 'object') {
throw Error('states expected to be an object or array, got ' + typeof states);
throw new Error('states expected to be an object or array, got ' + typeof states);
}

const validatorFn = useRef(validator);
Expand Down

0 comments on commit 056875b

Please sign in to comment.