From c367c0583219ece7464c382c0e34d8ce8c970b81 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Thu, 1 Oct 2026 12:42:01 +0900 Subject: [PATCH] test(lit-query/createMutationController): add test for using mutation defaults --- .../createMutationController.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/lit-query/src/__tests__/createMutationController.test.ts b/packages/lit-query/src/__tests__/createMutationController.test.ts index 1947dbcdeb..74a54e5564 100644 --- a/packages/lit-query/src/__tests__/createMutationController.test.ts +++ b/packages/lit-query/src/__tests__/createMutationController.test.ts @@ -179,6 +179,41 @@ describe('createMutationController', () => { expect(host.shadowRoot).toHaveTextContent('data: 3') }) + it('should be able to use mutation defaults', async () => { + const key = queryKey() + + queryClient.setMutationDefaults(key, { + mutationFn: (text: string) => sleep(10).then(() => text), + }) + + class Host extends LitElement { + readonly mutation = createMutationController( + this, + { mutationKey: key }, + queryClient, + ) + + override render() { + const { status, data } = this.mutation() + return html`status: ${status}, data: ${data ?? 'none'}` + } + } + customElements.define(generateElementName(), Host) + const host = new Host() + container.append(host) + await host.updateComplete + + expect(host.shadowRoot).toHaveTextContent('status: idle, data: none') + + host.mutation.mutate('todo') + await vi.advanceTimersByTimeAsync(0) + expect(host.shadowRoot).toHaveTextContent('status: pending, data: none') + + await vi.advanceTimersByTimeAsync(10) + expect(host.mutation().data).toBe('todo') + expect(host.shadowRoot).toHaveTextContent('status: success, data: todo') + }) + it('should transition from idle to pending to success', async () => { class Host extends LitElement { readonly mutation = createMutationController(