Skip to content

Commit

Permalink
Merge pull request #4394 from easyops-cn/steve/v3-fix-tpl-methods
Browse files Browse the repository at this point in the history
fix(): tpl proxied methods should return
  • Loading branch information
qiaofengxi authored Aug 9, 2024
2 parents f75b80b + 5dfb2ed commit f3561da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions packages/runtime/src/CustomTemplates.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,14 @@ describe("customTemplates", () => {
runtimeContext,
};
(refA.element as any).propA = "a2";
const methodM = ((refA.element as any).methodM = jest.fn());
const methodM = ((refA.element as any).methodM = jest.fn(() => "M"));
const refB: RuntimeBrick = {
type: "div",
element: document.createElement("div"),
runtimeContext,
};
(refB.element as any).propC = "b2";
const methodL = ((refB.element as any).methodL = jest.fn());
const methodL = ((refB.element as any).methodL = jest.fn(() => "L"));
const hostBrick: RuntimeBrick = {
type: "tpl-proxy",
tplHostMetadata: {
Expand Down Expand Up @@ -172,10 +172,12 @@ describe("customTemplates", () => {
expect(tpl.propA).toBe("a2");
expect(tpl.propB).toBe("b2");

(tpl as any).methodM("p");
const resultM = (tpl as any).methodM("p");
expect(resultM).toBe("M");
expect(methodM).toBeCalledTimes(1);
expect(methodM).toHaveBeenNthCalledWith(1, "p");
(tpl as any).methodN("q");
const resultN = (tpl as any).methodN("q");
expect(resultN).toBe("L");
expect(methodL).toBeCalledTimes(1);
expect(methodL).toHaveBeenNthCalledWith(1, "q");

Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/CustomTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class CustomTemplateRegistry {
string,
Function
>;
element[to.refMethod ?? from](...args);
return element[to.refMethod ?? from](...args);
},
enumerable: true,
});
Expand Down

0 comments on commit f3561da

Please sign in to comment.