File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
packages/solid-query/src/__tests__ Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,54 @@ describe('useMutationState', () => {
1818 vi . useRealTimers ( )
1919 } )
2020
21+ it ( 'should return all mutation states when called without options' , async ( ) => {
22+ const queryClient = new QueryClient ( )
23+ const mutationKey = [ 'mutation' ]
24+
25+ function States ( ) {
26+ const mutationStates = useMutationState ( )
27+
28+ return < div > count: { mutationStates ( ) . length } </ div >
29+ }
30+
31+ function Mutate ( ) {
32+ const mutation = useMutation ( ( ) => ( {
33+ mutationKey,
34+ mutationFn : ( input : number ) => sleep ( 150 ) . then ( ( ) => 'data' + input ) ,
35+ } ) )
36+
37+ return (
38+ < div >
39+ < button onClick = { ( ) => mutation . mutate ( 1 ) } > mutate</ button >
40+ </ div >
41+ )
42+ }
43+
44+ function Page ( ) {
45+ return (
46+ < div >
47+ < States />
48+ < Mutate />
49+ </ div >
50+ )
51+ }
52+
53+ const rendered = render ( ( ) => (
54+ < QueryClientProvider client = { queryClient } >
55+ < Page />
56+ </ QueryClientProvider >
57+ ) )
58+
59+ expect ( rendered . getByText ( 'count: 0' ) ) . toBeInTheDocument ( )
60+
61+ fireEvent . click ( rendered . getByRole ( 'button' , { name : / m u t a t e / i } ) )
62+ await vi . advanceTimersByTimeAsync ( 0 )
63+ expect ( rendered . getByText ( 'count: 1' ) ) . toBeInTheDocument ( )
64+
65+ await vi . advanceTimersByTimeAsync ( 150 )
66+ expect ( rendered . getByText ( 'count: 1' ) ) . toBeInTheDocument ( )
67+ } )
68+
2169 it ( 'should return variables after calling mutate' , async ( ) => {
2270 const queryClient = new QueryClient ( )
2371 const variables : Array < Array < unknown > > = [ ]
You can’t perform that action at this time.
0 commit comments