fix: missing widgets (#3541)
This commit is contained in:
parent
76732f7208
commit
6933bf6ee1
@ -147,26 +147,4 @@ describe('registry', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('getWidget', () => {
|
|
||||||
it('should throw on missing widget', () => {
|
|
||||||
const { getWidget } = require('../registry');
|
|
||||||
|
|
||||||
expect(() => getWidget('Unknown')).toThrow(
|
|
||||||
new Error(
|
|
||||||
`Could not find widget 'Unknown'. Please make sure the widget name is configured correctly or register it via 'registerwidget'.`,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should throw on missing widget and suggest lowercase name', () => {
|
|
||||||
const { getWidget, registerWidget } = require('../registry');
|
|
||||||
|
|
||||||
registerWidget('string', {});
|
|
||||||
|
|
||||||
expect(() => getWidget('String')).toThrow(
|
|
||||||
new Error(`Could not find widget 'String'. Did you mean 'string'?`),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
@ -113,16 +113,7 @@ export function registerWidget(name, control, preview) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
export function getWidget(name) {
|
export function getWidget(name) {
|
||||||
const widget = registry.widgets[name];
|
return registry.widgets[name];
|
||||||
if (!widget) {
|
|
||||||
const nameLowerCase = name.toLowerCase();
|
|
||||||
const hasLowerCase = !!registry.widgets[nameLowerCase];
|
|
||||||
const message = hasLowerCase
|
|
||||||
? `Could not find widget '${name}'. Did you mean '${nameLowerCase}'?`
|
|
||||||
: `Could not find widget '${name}'. Please make sure the widget name is configured correctly or register it via 'registerwidget'.`;
|
|
||||||
throw new Error(message);
|
|
||||||
}
|
|
||||||
return widget;
|
|
||||||
}
|
}
|
||||||
export function getWidgets() {
|
export function getWidgets() {
|
||||||
return produce(Object.entries(registry.widgets), draft => {
|
return produce(Object.entries(registry.widgets), draft => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user