Skip to content

Commit

Permalink
fix(yupResolver): Yup fails silently (#328) (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisre committed Jan 18, 2022
1 parent ce79a77 commit 0f016f4
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
restoreMocks: true,
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
testPathIgnorePatterns: ['/__fixtures__/', '/\\.'],
moduleNameMapper: {
'^@hookform/resolvers$': '<rootDir>/src',
},
Expand Down
18 changes: 18 additions & 0 deletions yup/src/__tests__/yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,22 @@ describe('validateWithSchema', () => {
errors: { name: { message: 'Email or name are required', type: 'name' } },
});
});

it('should throw an error without inner property', (done) => {
const schemaWithWhen = yup.object({
name: yup.string().required(),
value: yup.string().when('name', {
is: 'test',
then: yup.number().required(),
}),
});

// @ts-expect-error
yupResolver(schemaWithWhen)({ name: 'test', value: '' }).catch((e) => {
expect(e).toMatchInlineSnapshot(
`[TypeError: You cannot \`concat()\` schema's of different types: string and number]`,
);
done();
});
});
});
6 changes: 5 additions & 1 deletion yup/src/yup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export const yupResolver = <TFieldValues extends FieldValues>(
}),
errors: {},
};
} catch (e) {
} catch (e: any) {
if (!e.inner) {
throw e;
}

const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria);
return {
values: {},
Expand Down

0 comments on commit 0f016f4

Please sign in to comment.