From af94bc18df29febe414809e032f8a087c32f75f7 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Thu, 1 Oct 2026 01:00:47 +0900 Subject: [PATCH] test(lit-query/useMutationState): add test for not processing mutation cache updates while disconnected --- .../src/__tests__/useMutationState.test.ts | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/packages/lit-query/src/__tests__/useMutationState.test.ts b/packages/lit-query/src/__tests__/useMutationState.test.ts index f2de740132..7e6e356cc2 100644 --- a/packages/lit-query/src/__tests__/useMutationState.test.ts +++ b/packages/lit-query/src/__tests__/useMutationState.test.ts @@ -258,6 +258,52 @@ describe('useMutationState', () => { expect(host.shadowRoot).toHaveTextContent('statuses: success') }) + it('should not process mutation cache updates while disconnected', async () => { + class Producer extends LitElement { + readonly mutation = createMutationController( + this, + { + mutationFn: (value: number) => sleep(10).then(() => value + 10), + }, + queryClient, + ) + } + customElements.define(generateElementName(), Producer) + + class Host extends LitElement { + updatesRequested = 0 + + readonly mutationStatuses = useMutationState( + this, + { + select: (item) => item.state.status, + }, + queryClient, + ) + + override requestUpdate( + ...args: Parameters + ): void { + this.updatesRequested += 1 + super.requestUpdate(...args) + } + } + customElements.define(generateElementName(), Host) + const producer = new Producer() + const host = new Host() + container.append(producer, host) + const { mutation } = producer + await host.updateComplete + + host.remove() + await host.updateComplete + const updatesAfterDisconnect = host.updatesRequested + + mutation.mutate(1) + await vi.advanceTimersByTimeAsync(10) + expect(host.updatesRequested).toBe(updatesAfterDisconnect) + }) + it('should return the states of all mutations when options are omitted', async () => { class Producer extends LitElement { readonly mutation1 = createMutationController(this, {