The registry from getTestRegistry is frozen
Detect
- A test that assigns into the result of
getTestRegistry(), or into itsfields,templates,widgetsortemplates.ButtonTemplates, such asregistry.widgets.MyWidget = MyWidget. - The test throws a
TypeErrorsuch asCannot assign to read only propertyorCannot add property MyWidget, object is not extensible.
Change
getTestRegistry() from @rjsf/core/testing (see getTestRegistry moved to @rjsf/core/testing) freezes the registry it returns, along with its fields, templates and widgets maps, the nested ButtonTemplates and the presentation. A mutation now throws instead of silently affecting later assertions.
Pass your fields, templates and widgets to getTestRegistry() as arguments, or spread the frozen registry into a new object:
const registry = getTestRegistry(schema);
-registry.widgets.MyWidget = MyWidget;
+const testRegistry = { ...registry, widgets: { ...registry.widgets, MyWidget } };
The freeze is shallow by design. Objects you own, such as formContext, rootSchema and the validator's internal caches, stay unfrozen. The registry type is read-only as well, see Registry members are read-only.
Verify
The tests that used to mutate the registry pass, and no test throws on assigning into it.
Also read: