Skip to content

Commit 0f016f4

Browse files
authored
fix(yupResolver): Yup fails silently (#328) (#320)
1 parent ce79a77 commit 0f016f4

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module.exports = {
33
restoreMocks: true,
44
testMatch: ['**/__tests__/**/*.+(js|jsx|ts|tsx)'],
55
transformIgnorePatterns: ['[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$'],
6+
testPathIgnorePatterns: ['/__fixtures__/', '/\\.'],
67
moduleNameMapper: {
78
'^@hookform/resolvers$': '<rootDir>/src',
89
},

yup/src/__tests__/yup.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,22 @@ describe('validateWithSchema', () => {
290290
errors: { name: { message: 'Email or name are required', type: 'name' } },
291291
});
292292
});
293+
294+
it('should throw an error without inner property', (done) => {
295+
const schemaWithWhen = yup.object({
296+
name: yup.string().required(),
297+
value: yup.string().when('name', {
298+
is: 'test',
299+
then: yup.number().required(),
300+
}),
301+
});
302+
303+
// @ts-expect-error
304+
yupResolver(schemaWithWhen)({ name: 'test', value: '' }).catch((e) => {
305+
expect(e).toMatchInlineSnapshot(
306+
`[TypeError: You cannot \`concat()\` schema's of different types: string and number]`,
307+
);
308+
done();
309+
});
310+
});
293311
});

yup/src/yup.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ export const yupResolver = <TFieldValues extends FieldValues>(
8282
}),
8383
errors: {},
8484
};
85-
} catch (e) {
85+
} catch (e: any) {
86+
if (!e.inner) {
87+
throw e;
88+
}
89+
8690
const parsedErrors = parseErrorSchema(e, validateAllFieldCriteria);
8791
return {
8892
values: {},

0 commit comments

Comments
 (0)