fix(demos): snapshot validated values before asynchronous submissions
This commit is contained in:
@@ -477,3 +477,35 @@ it("keeps the baseline preview inventories and exact fieldset submission feedbac
|
||||
alert.mockRestore();
|
||||
w.unmount();
|
||||
});
|
||||
|
||||
it.each(["changed-query", "x"])(
|
||||
"keeps the submitted search-field snapshot when pending input changes to %s",
|
||||
async (changed) => {
|
||||
const { default: Demo } =
|
||||
await import("../apps/docs/demos/search-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[type=search]");
|
||||
await input.setValue("original-query");
|
||||
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("Search submitted:");
|
||||
expect(String((log.mock.calls[0][1] as { query: unknown }).query)).toBe(
|
||||
"original-query",
|
||||
);
|
||||
expect((input.element as HTMLInputElement).value).toBe("");
|
||||
} finally {
|
||||
w.unmount();
|
||||
log.mockRestore();
|
||||
vi.useRealTimers();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user