

























@@ -80,6 +80,11 @@ function dispatchPointer(target: EventTarget, type: string, clientX: number) {
8080);
8181}
828283+function expectLastResizeRatio(resized: ReturnType<typeof vi.fn>, splitRatio: number) {
84+const event = resized.mock.lastCall?.[0] as CustomEvent<{ splitRatio: number }> | undefined;
85+expect(event?.detail.splitRatio).toBe(splitRatio);
86+}
87+8388describe("resizable-divider", () => {
8489beforeEach(() => {
8590if (!globalThis.PointerEvent) {
@@ -135,9 +140,7 @@ describe("resizable-divider", () => {
135140});
136141divider.dispatchEvent(arrowLeft);
137142expect(arrowLeft.defaultPrevented).toBe(true);
138-expect(resized).toHaveBeenLastCalledWith(
139-expect.objectContaining({ detail: { splitRatio: 0.58 } }),
140-);
143+expectLastResizeRatio(resized, 0.58);
141144142145const arrowRight = new KeyboardEvent("keydown", {
143146key: "ArrowRight",
@@ -147,19 +150,13 @@ describe("resizable-divider", () => {
147150});
148151divider.dispatchEvent(arrowRight);
149152expect(arrowRight.defaultPrevented).toBe(true);
150-expect(resized).toHaveBeenLastCalledWith(
151-expect.objectContaining({ detail: { splitRatio: 0.65 } }),
152-);
153+expectLastResizeRatio(resized, 0.65);
153154154155divider.dispatchEvent(new KeyboardEvent("keydown", { key: "Home", bubbles: true }));
155-expect(resized).toHaveBeenLastCalledWith(
156-expect.objectContaining({ detail: { splitRatio: 0.4 } }),
157-);
156+expectLastResizeRatio(resized, 0.4);
158157159158divider.dispatchEvent(new KeyboardEvent("keydown", { key: "End", bubbles: true }));
160-expect(resized).toHaveBeenLastCalledWith(
161-expect.objectContaining({ detail: { splitRatio: 0.7 } }),
162-);
159+expectLastResizeRatio(resized, 0.7);
163160});
164161165162it("uses pointer events for mouse, pen, and touch dragging", async () => {
@@ -179,9 +176,7 @@ describe("resizable-divider", () => {
179176expect(setPointerCapture).toHaveBeenCalledWith(7);
180177181178dispatchPointer(document, "pointermove", 220);
182-expect(resized).toHaveBeenLastCalledWith(
183-expect.objectContaining({ detail: { splitRatio: 0.7 } }),
184-);
179+expectLastResizeRatio(resized, 0.7);
185180186181dispatchPointer(document, "pointerup", 220);
187182expect(divider.classList.contains("dragging")).toBe(false);
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。