diff --git a/CHANGELOG.md b/CHANGELOG.md index 904e8564bb..e9bd28690e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,7 @@ should change the heading of the (upcoming) version to include a major version b - `ErrorListProps`, `FieldProps`, `FieldTemplateProps`, `ArrayFieldTemplateProps` and `WidgetProps` - Update `mergeDefaultsWithFormData` to properly handle overriding `undefined` formData with a `null` default value, fixing [#4734](https://github.com/rjsf-team/react-jsonschema-form/issues/4734) - Fixed object reference sharing in arrays with minItems when using oneOf schemas, fixing [#4756](https://github.com/rjsf-team/react-jsonschema-form/issues/4756) +- Updated `getWigets()` to output the `schema` when throwing errors, fixing [#4731](https://github.com/rjsf-team/react-jsonschema-form/issues/4731) ## Dev / docs / playground diff --git a/packages/utils/src/getWidget.tsx b/packages/utils/src/getWidget.tsx index c61ff66fdb..06f23be5db 100644 --- a/packages/utils/src/getWidget.tsx +++ b/packages/utils/src/getWidget.tsx @@ -110,7 +110,7 @@ export default function getWidget>(function TestRefWidget( props: Partial, @@ -88,19 +91,21 @@ const widgetProps: WidgetProps = { describe('getWidget()', () => { it('should fail if widget has incorrect type', () => { - expect(() => getWidget(schema)).toThrow('Unsupported widget definition: undefined'); + expect(() => getWidget(schema)).toThrow(`Unsupported widget definition: undefined in schema: ${schemaStr}`); }); it('should fail if widget has no type property', () => { - expect(() => getWidget(schema, 'blabla')).toThrow(`No widget for type 'object'`); + expect(() => getWidget(schema, 'blabla')).toThrow(`No widget for type 'object' in schema: ${schemaStr}`); }); it('should fail if schema `type` has no widget property', () => { - expect(() => getWidget(subschema, 'blabla')).toThrow(`No widget 'blabla' for type 'boolean'`); + expect(() => getWidget(subschema, 'blabla')).toThrow( + `No widget 'blabla' for type 'boolean' in schema: ${subschemaStr}`, + ); }); it('should fail if schema has no type property', () => { - expect(() => getWidget({}, 'blabla')).toThrow(`No widget 'blabla' for type 'undefined'`); + expect(() => getWidget({}, 'blabla')).toThrow(`No widget 'blabla' for type 'undefined' in schema: {}`); }); it('should return widget if in registered widgets', () => {