Skip to content

Commit 99b4b26

Browse files
authored
Merge pull request #4288 from easyops-cn/sailorshe/v3/fixCustomEditorThrowError
fix(): customEditor not throw error
2 parents f05bbe5 + 1f22b3a commit 99b4b26

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

packages/runtime/src/CustomEditors.spec.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { customEditors } from "./CustomEditors.js";
22

3+
const mockConsoleError = jest
4+
.spyOn(console, "error")
5+
.mockImplementation(() => void 0);
6+
37
describe("CustomEditors", () => {
48
it("should work", () => {
59
function objectEntries(object: Record<string, any>): [string, any][] {
@@ -20,9 +24,11 @@ describe("CustomEditors", () => {
2024
).toEqual([["quality", "good"]]);
2125
expect(customEditors.get("basic-bricks.general-button-editor")?.()).toBe(5);
2226

27+
expect(mockConsoleError).toHaveBeenCalledTimes(0);
28+
2329
// Can't register duplicated editors in the same namespace.
24-
expect(() => {
25-
customEditors.define("eo-button--editor", () => void 0);
26-
}).toThrowError();
30+
customEditors.define("eo-button--editor", () => void 0);
31+
32+
expect(mockConsoleError).toHaveBeenCalledTimes(1);
2733
});
2834
});

packages/runtime/src/CustomEditors.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ class CustomEditorRegistry {
33

44
define(editorName: string, editorFunc: Function) {
55
if (this.#registry.has(editorName)) {
6-
throw new Error(`Custom editor of "${editorName}" already registered`);
6+
// eslint-disable-next-line no-console
7+
console.error(`Custom editor of "${editorName}" already registered`);
8+
return;
79
}
810

911
this.#registry.set(editorName, editorFunc);

0 commit comments

Comments
 (0)