@@ -150,6 +150,73 @@ describe('MobxQuery', () => {
150150 } ) ;
151151 } ) ;
152152
153+ describe ( '"enabled" reactive parameter' , ( ) => {
154+ it ( 'should be reactive after change queryKey' , ( ) => {
155+ const mobxQuery = new MobxQueryMock ( {
156+ queryKey : [ 'test' , 0 ] as const ,
157+ enabled : ( { queryKey } ) => queryKey [ 1 ] > 0 ,
158+ queryFn : ( ) => 100 ,
159+ } ) ;
160+
161+ mobxQuery . update ( { queryKey : [ 'test' , 1 ] as const } ) ;
162+
163+ expect ( mobxQuery . spies . queryFn ) . toBeCalledTimes ( 1 ) ;
164+ expect ( mobxQuery . spies . queryFn ) . nthReturnedWith ( 1 , 100 ) ;
165+ } ) ;
166+
167+ it ( 'should be reactive dependent on another query (runs before declartion)' , ( ) => {
168+ const disabledMobxQuery = new MobxQueryMock ( {
169+ queryKey : [ 'test' , 0 ] as const ,
170+ enabled : ( { queryKey } ) => queryKey [ 1 ] > 0 ,
171+ queryFn : ( ) => 100 ,
172+ } ) ;
173+
174+ disabledMobxQuery . update ( { queryKey : [ 'test' , 1 ] as const } ) ;
175+
176+ const dependentMobxQuery = new MobxQueryMock ( {
177+ options : ( ) => ( {
178+ enabled : ! ! disabledMobxQuery . options . enabled ,
179+ queryKey : [ ...disabledMobxQuery . options . queryKey , 'dependent' ] ,
180+ } ) ,
181+ queryFn : ( { queryKey } ) => queryKey ,
182+ } ) ;
183+
184+ expect ( dependentMobxQuery . spies . queryFn ) . toBeCalledTimes ( 1 ) ;
185+ expect ( dependentMobxQuery . spies . queryFn ) . nthReturnedWith ( 1 , [
186+ 'test' ,
187+ 1 ,
188+ 'dependent' ,
189+ ] ) ;
190+ } ) ;
191+
192+ it ( 'should be reactive dependent on another query (runs after declaration)' , ( ) => {
193+ const tempDisabledMobxQuery = new MobxQueryMock ( {
194+ queryKey : [ 'test' , 0 ] as const ,
195+ enabled : ( { queryKey } ) => queryKey [ 1 ] > 0 ,
196+ queryFn : ( ) => 100 ,
197+ } ) ;
198+
199+ const dependentMobxQuery = new MobxQueryMock ( {
200+ options : ( ) => ( {
201+ enabled : ! ! tempDisabledMobxQuery . options . enabled ,
202+ queryKey : [ ...tempDisabledMobxQuery . options . queryKey , 'dependent' ] ,
203+ } ) ,
204+ queryFn : ( { queryKey } ) => queryKey ,
205+ } ) ;
206+
207+ tempDisabledMobxQuery . update ( { queryKey : [ 'test' , 1 ] as const } ) ;
208+
209+ expect ( dependentMobxQuery . spies . queryFn ) . toBeCalledTimes ( 1 ) ;
210+ // результат с 0 потому что options.enabled у первой квери - это функция и
211+ // !!tempDisabledMobxQuery.options.enabled будет всегда true
212+ expect ( dependentMobxQuery . spies . queryFn ) . nthReturnedWith ( 1 , [
213+ 'test' ,
214+ 0 ,
215+ 'dependent' ,
216+ ] ) ;
217+ } ) ;
218+ } ) ;
219+
153220 describe ( '"options" reactive parameter' , ( ) => {
154221 it ( '"options.queryKey" should updates query' , async ( ) => {
155222 const boxCounter = observable . box ( 0 ) ;
0 commit comments