fix(demos): snapshot validated values before asynchronous submissions

This commit is contained in:
maoyingjie
2026-10-28 15:05:09 +08:00
parent 49dd67afac
commit b0f32796cb
6 changed files with 102 additions and 3 deletions
+32
View File
@@ -332,3 +332,35 @@ describe("NumberField public contracts", () => {
);
});
});
it.each(["3", "5"])(
"keeps the submitted number-field snapshot when pending input changes to %s",
async (changed) => {
const { default: Demo } =
await import("../apps/docs/demos/number-field-form-example.vue");
const w = mount(Demo, { attachTo: document.body });
const log = vi.spyOn(console, "log").mockImplementation(() => {});
vi.useFakeTimers();
try {
const input = w.get("input[role=spinbutton]");
await input.setValue("2");
await input.trigger("blur");
await w.get("form").trigger("submit");
expect(w.get('button[type="submit"]').text()).toContain("…");
await input.setValue(changed);
await input.trigger("blur");
await w.get("form").trigger("submit");
await vi.advanceTimersByTimeAsync(1500);
expect(log).toHaveBeenCalledTimes(1);
expect(log.mock.calls[0][0]).toBe("Order submitted:");
expect(
String((log.mock.calls[0][1] as { quantity: unknown }).quantity),
).toBe("2");
expect((input.element as HTMLInputElement).value).toBe("");
} finally {
w.unmount();
log.mockRestore();
vi.useRealTimers();
}
},
);