| ... | ... | @@ -94,6 +94,48 @@ test("useMutate - global error and success handling", async () => { |
| 94 | 94 | ]); |
| 95 | 95 | }); |
| 96 | 96 | |
| 97 | test("useMutate - a failure before the pending delay never leaves isPending stuck", async () => { |
| 98 | vi.useFakeTimers({ shouldAdvanceTime: true }); |
| 99 | const user = userEvent.setup({ delay: null }); |
| 100 | |
| 101 | const { client } = createTestMutationClient(); |
| 102 | const s = new IterableStream<string>(); |
| 103 | |
| 104 | const mutTest = client.define({ |
| 105 | id: "test-fast-failure", |
| 106 | mutate: async () => { |
| 107 | return (await s.next()).value; |
| 108 | }, |
| 109 | describe: "Test the action", |
| 110 | describeResult: null, |
| 111 | optimistic: () => {}, |
| 112 | }); |
| 113 | |
| 114 | let state = {}; |
| 115 | function TestComponent() { |
| 116 | const { run, isMutating, isPending, errorMessage } = useMutate(mutTest); |
| 117 | state = { isMutating, isPending, errorMessage }; |
| 118 | return ( |
| 119 | <button data-testid="a" onClick={() => run()}> |
| 120 | button |
| 121 | </button> |
| 122 | ); |
| 123 | } |
| 124 | |
| 125 | render(<TestComponent />); |
| 126 | await act(() => user.click(screen.getByTestId("a"))); |
| 127 | await act(async () => { |
| 128 | s.throw(new Error("damn!")); |
| 129 | vi.advanceTimersByTime(50); |
| 130 | }); |
| 131 | await act(() => vi.advanceTimersByTime(500)); |
| 132 | assertEquals(state, { |
| 133 | isMutating: false, |
| 134 | isPending: false, |
| 135 | errorMessage: "Could not test the action: damn!", |
| 136 | }); |
| 137 | }); |
| 138 | |
| 97 | 139 | test("useMutate - local error and success handling", async () => { |
| 98 | 140 | vi.useFakeTimers({ shouldAdvanceTime: true }); |
| 99 | 141 | const user = userEvent.setup({ delay: null }); |