Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

queryObserver.test.tsx

835 lines23.0 KB

1import { QueryObserver, focusManager } from '..'
2import {
3 createQueryClient,
4 expectType,
5 mockLogger,
6 queryKey,
7 sleep,
8} from './utils'
9import type { QueryClient, QueryObserverResult } from '..'
10​
11describe('queryObserver', () => {
12 let queryClient: QueryClient
13​
14 beforeEach(() => {
15 queryClient = createQueryClient()
16 queryClient.mount()
17 })
18​
19 afterEach(() => {
20 queryClient.clear()
21 })
22​
23 test('should trigger a fetch when subscribed', async () => {
24 const key = queryKey()
25 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
26 const observer = new QueryObserver(queryClient, { queryKey: key, queryFn })
27 const unsubscribe = observer.subscribe(() => undefined)
28 await sleep(1)
29 unsubscribe()
30 expect(queryFn).toHaveBeenCalledTimes(1)
31 })
32​
33 test('should notify when switching query', async () => {
34 const key1 = queryKey()
35 const key2 = queryKey()
36 const results: QueryObserverResult[] = []
37 const observer = new QueryObserver(queryClient, {
38 queryKey: key1,
39 queryFn: () => 1,
40 })
41 const unsubscribe = observer.subscribe((result) => {
42 results.push(result)
43 })
44 await sleep(1)
45 observer.setOptions({ queryKey: key2, queryFn: () => 2 })
46 await sleep(1)
47 unsubscribe()
48 expect(results.length).toBe(4)
49 expect(results[0]).toMatchObject({ data: undefined, status: 'loading' })
50 expect(results[1]).toMatchObject({ data: 1, status: 'success' })
51 expect(results[2]).toMatchObject({ data: undefined, status: 'loading' })
52 expect(results[3]).toMatchObject({ data: 2, status: 'success' })
53 })
54​
55 test('should be able to fetch with a selector', async () => {
56 const key = queryKey()
57 const observer = new QueryObserver(queryClient, {
58 queryKey: key,
59 queryFn: () => ({ count: 1 }),
60 select: (data) => ({ myCount: data.count }),
61 })
62 let observerResult
63 const unsubscribe = observer.subscribe((result) => {
64 expectType<QueryObserverResult<{ myCount: number }>>(result)
65 observerResult = result
66 })
67 await sleep(1)
68 unsubscribe()
69 expect(observerResult).toMatchObject({ data: { myCount: 1 } })
70 })
71​
72 test('should be able to fetch with a selector using the fetch method', async () => {
73 const key = queryKey()
74 const observer = new QueryObserver(queryClient, {
75 queryKey: key,
76 queryFn: () => ({ count: 1 }),
77 select: (data) => ({ myCount: data.count }),
78 })
79 const observerResult = await observer.refetch()
80 expectType<{ myCount: number } | undefined>(observerResult.data)
81 expect(observerResult.data).toMatchObject({ myCount: 1 })
82 })
83​
84 test('should be able to fetch with a selector and object syntax', async () => {
85 const key = queryKey()
86 const observer = new QueryObserver(queryClient, {
87 queryKey: key,
88 queryFn: () => ({ count: 1 }),
89 select: (data) => ({ myCount: data.count }),
90 })
91 let observerResult
92 const unsubscribe = observer.subscribe((result) => {
93 observerResult = result
94 })
95 await sleep(1)
96 unsubscribe()
97 expect(observerResult).toMatchObject({ data: { myCount: 1 } })
98 })
99​
100 test('should run the selector again if the data changed', async () => {
101 const key = queryKey()
102 let count = 0
103 const observer = new QueryObserver(queryClient, {
104 queryKey: key,
105 queryFn: () => ({ count }),
106 select: (data) => {
107 count++
108 return { myCount: data.count }
109 },
110 })
111 const observerResult1 = await observer.refetch()
112 const observerResult2 = await observer.refetch()
113 expect(count).toBe(2)
114 expect(observerResult1.data).toMatchObject({ myCount: 0 })
115 expect(observerResult2.data).toMatchObject({ myCount: 1 })
116 })
117​
118 test('should run the selector again if the selector changed', async () => {
119 const key = queryKey()
120 let count = 0
121 const results: QueryObserverResult[] = []
122 const queryFn = () => ({ count: 1 })
123 const select1 = (data: ReturnType<typeof queryFn>) => {
124 count++
125 return { myCount: data.count }
126 }
127 const select2 = (_data: ReturnType<typeof queryFn>) => {
128 count++
129 return { myCount: 99 }
130 }
131 const observer = new QueryObserver(queryClient, {
132 queryKey: key,
133 queryFn,
134 select: select1,
135 })
136 const unsubscribe = observer.subscribe((result) => {
137 results.push(result)
138 })
139 await sleep(1)
140 observer.setOptions({
141 queryKey: key,
142 queryFn,
143 select: select2,
144 })
145 await sleep(1)
146 await observer.refetch()
147 unsubscribe()
148 expect(count).toBe(2)
149 expect(results.length).toBe(5)
150 expect(results[0]).toMatchObject({
151 status: 'loading',
152 isFetching: true,
153 data: undefined,
154 })
155 expect(results[1]).toMatchObject({
156 status: 'success',
157 isFetching: false,
158 data: { myCount: 1 },
159 })
160 expect(results[2]).toMatchObject({
161 status: 'success',
162 isFetching: false,
163 data: { myCount: 99 },
164 })
165 expect(results[3]).toMatchObject({
166 status: 'success',
167 isFetching: true,
168 data: { myCount: 99 },
169 })
170 expect(results[4]).toMatchObject({
171 status: 'success',
172 isFetching: false,
173 data: { myCount: 99 },
174 })
175 })
176​
177 test('should not run the selector again if the data and selector did not change', async () => {
178 const key = queryKey()
179 let count = 0
180 const results: QueryObserverResult[] = []
181 const queryFn = () => ({ count: 1 })
182 const select = (data: ReturnType<typeof queryFn>) => {
183 count++
184 return { myCount: data.count }
185 }
186 const observer = new QueryObserver(queryClient, {
187 queryKey: key,
188 queryFn,
189 select,
190 })
191 const unsubscribe = observer.subscribe((result) => {
192 results.push(result)
193 })
194 await sleep(1)
195 observer.setOptions({
196 queryKey: key,
197 queryFn,
198 select,
199 })
200 await sleep(1)
201 await observer.refetch()
202 unsubscribe()
203 expect(count).toBe(1)
204 expect(results.length).toBe(4)
205 expect(results[0]).toMatchObject({
206 status: 'loading',
207 isFetching: true,
208 data: undefined,
209 })
210 expect(results[1]).toMatchObject({
211 status: 'success',
212 isFetching: false,
213 data: { myCount: 1 },
214 })
215 expect(results[2]).toMatchObject({
216 status: 'success',
217 isFetching: true,
218 data: { myCount: 1 },
219 })
220 expect(results[3]).toMatchObject({
221 status: 'success',
222 isFetching: false,
223 data: { myCount: 1 },
224 })
225 })
226​
227 test('should not run the selector again if the data did not change', async () => {
228 const key = queryKey()
229 let count = 0
230 const observer = new QueryObserver(queryClient, {
231 queryKey: key,
232 queryFn: () => ({ count: 1 }),
233 select: (data) => {
234 count++
235 return { myCount: data.count }
236 },
237 })
238 const observerResult1 = await observer.refetch()
239 const observerResult2 = await observer.refetch()
240 expect(count).toBe(1)
241 expect(observerResult1.data).toMatchObject({ myCount: 1 })
242 expect(observerResult2.data).toMatchObject({ myCount: 1 })
243 })
244​
245 test('should always run the selector again if selector throws an error and selector is not referentially stable', async () => {
246 const key = queryKey()
247 const results: QueryObserverResult[] = []
248 const queryFn = async () => {
249 await sleep(10)
250 return { count: 1 }
251 }
252 const observer = new QueryObserver(queryClient, {
253 queryKey: key,
254 queryFn,
255 select: () => {
256 throw new Error('selector error')
257 },
258 })
259 const unsubscribe = observer.subscribe((result) => {
260 results.push(result)
261 })
262 await sleep(50)
263 await observer.refetch()
264 unsubscribe()
265 expect(results[0]).toMatchObject({
266 status: 'loading',
267 isFetching: true,
268 data: undefined,
269 })
270 expect(results[1]).toMatchObject({
271 status: 'error',
272 isFetching: false,
273 data: undefined,
274 })
275 expect(results[2]).toMatchObject({
276 status: 'error',
277 isFetching: true,
278 data: undefined,
279 })
280 expect(results[3]).toMatchObject({
281 status: 'error',
282 isFetching: false,
283 data: undefined,
284 })
285 })
286​
287 test('should return stale data if selector throws an error', async () => {
288 const key = queryKey()
289 const results: QueryObserverResult[] = []
290 let shouldError = false
291 const error = new Error('select error')
292 const observer = new QueryObserver(queryClient, {
293 queryKey: key,
294 retry: 0,
295 queryFn: async () => {
296 await sleep(10)
297 return shouldError ? 2 : 1
298 },
299 select: (num) => {
300 if (shouldError) {
301 throw error
302 }
303 shouldError = true
304 return String(num)
305 },
306 })
307​
308 const unsubscribe = observer.subscribe((result) => {
309 results.push(result)
310 })
311 await sleep(50)
312 await observer.refetch()
313 unsubscribe()
314​
315 expect(results[0]).toMatchObject({
316 status: 'loading',
317 isFetching: true,
318 data: undefined,
319 error: null,
320 })
321 expect(results[1]).toMatchObject({
322 status: 'success',
323 isFetching: false,
324 data: '1',
325 error: null,
326 })
327 expect(results[2]).toMatchObject({
328 status: 'success',
329 isFetching: true,
330 data: '1',
331 error: null,
332 })
333 expect(results[3]).toMatchObject({
334 status: 'error',
335 isFetching: false,
336 data: '1',
337 error,
338 })
339 })
340​
341 test('should structurally share the selector', async () => {
342 const key = queryKey()
343 let count = 0
344 const observer = new QueryObserver(queryClient, {
345 queryKey: key,
346 queryFn: () => ({ count: ++count }),
347 select: () => ({ myCount: 1 }),
348 })
349 const observerResult1 = await observer.refetch()
350 const observerResult2 = await observer.refetch()
351 expect(count).toBe(2)
352 expect(observerResult1.data).toBe(observerResult2.data)
353 })
354​
355 test('should not trigger a fetch when subscribed and disabled', async () => {
356 const key = queryKey()
357 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
358 const observer = new QueryObserver(queryClient, {
359 queryKey: key,
360 queryFn,
361 enabled: false,
362 })
363 const unsubscribe = observer.subscribe(() => undefined)
364 await sleep(1)
365 unsubscribe()
366 expect(queryFn).toHaveBeenCalledTimes(0)
367 })
368​
369 test('should not trigger a fetch when not subscribed', async () => {
370 const key = queryKey()
371 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
372 new QueryObserver(queryClient, { queryKey: key, queryFn })
373 await sleep(1)
374 expect(queryFn).toHaveBeenCalledTimes(0)
375 })
376​
377 test('should be able to watch a query without defining a query function', async () => {
378 const key = queryKey()
379 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
380 const callback = jest.fn()
381 const observer = new QueryObserver(queryClient, {
382 queryKey: key,
383 enabled: false,
384 })
385 const unsubscribe = observer.subscribe(callback)
386 await queryClient.fetchQuery(key, queryFn)
387 unsubscribe()
388 expect(queryFn).toHaveBeenCalledTimes(1)
389 expect(callback).toHaveBeenCalledTimes(2)
390 })
391​
392 test('should accept unresolved query config in update function', async () => {
393 const key = queryKey()
394 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
395 const observer = new QueryObserver(queryClient, {
396 queryKey: key,
397 enabled: false,
398 })
399 const results: QueryObserverResult<unknown>[] = []
400 const unsubscribe = observer.subscribe((x) => {
401 results.push(x)
402 })
403 observer.setOptions({ enabled: false, staleTime: 10 })
404 await queryClient.fetchQuery(key, queryFn)
405 await sleep(100)
406 unsubscribe()
407 expect(queryFn).toHaveBeenCalledTimes(1)
408 expect(results.length).toBe(3)
409 expect(results[0]).toMatchObject({ isStale: true })
410 expect(results[1]).toMatchObject({ isStale: false })
411 expect(results[2]).toMatchObject({ isStale: true })
412 })
413​
414 test('should be able to handle multiple subscribers', async () => {
415 const key = queryKey()
416 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
417 const observer = new QueryObserver<string>(queryClient, {
418 queryKey: key,
419 enabled: false,
420 })
421 const results1: QueryObserverResult<string>[] = []
422 const results2: QueryObserverResult<string>[] = []
423 const unsubscribe1 = observer.subscribe((x) => {
424 results1.push(x)
425 })
426 const unsubscribe2 = observer.subscribe((x) => {
427 results2.push(x)
428 })
429 await queryClient.fetchQuery(key, queryFn)
430 await sleep(50)
431 unsubscribe1()
432 unsubscribe2()
433 expect(queryFn).toHaveBeenCalledTimes(1)
434 expect(results1.length).toBe(2)
435 expect(results2.length).toBe(2)
436 expect(results1[0]).toMatchObject({ data: undefined })
437 expect(results1[1]).toMatchObject({ data: 'data' })
438 expect(results2[0]).toMatchObject({ data: undefined })
439 expect(results2[1]).toMatchObject({ data: 'data' })
440 })
441​
442 test('should stop retry when unsubscribing', async () => {
443 const key = queryKey()
444 let count = 0
445 const observer = new QueryObserver(queryClient, {
446 queryKey: key,
447 queryFn: () => {
448 count++
449 return Promise.reject<unknown>('reject')
450 },
451 retry: 10,
452 retryDelay: 50,
453 })
454 const unsubscribe = observer.subscribe(() => undefined)
455 await sleep(70)
456 unsubscribe()
457 await sleep(200)
458 expect(count).toBe(2)
459 })
460​
461 test('should clear interval when unsubscribing to a refetchInterval query', async () => {
462 const key = queryKey()
463​
464 const fetchData = () => Promise.resolve('data')
465 const observer = new QueryObserver(queryClient, {
466 queryKey: key,
467 queryFn: fetchData,
468 cacheTime: 0,
469 refetchInterval: 1,
470 })
471 const unsubscribe = observer.subscribe(() => undefined)
472 // @ts-expect-error
473 expect(observer.refetchIntervalId).not.toBeUndefined()
474 unsubscribe()
475 // @ts-expect-error
476 expect(observer.refetchIntervalId).toBeUndefined()
477 await sleep(10)
478 expect(queryClient.getQueryCache().find(key)).toBeUndefined()
479 })
480​
481 test('uses placeholderData as non-cache data when loading a query with no data', async () => {
482 const key = queryKey()
483 const observer = new QueryObserver(queryClient, {
484 queryKey: key,
485 queryFn: () => 'data',
486 placeholderData: 'placeholder',
487 })
488​
489 expect(observer.getCurrentResult()).toMatchObject({
490 status: 'success',
491 data: 'placeholder',
492 })
493​
494 const results: QueryObserverResult<unknown>[] = []
495​
496 const unsubscribe = observer.subscribe((x) => {
497 results.push(x)
498 })
499​
500 await sleep(10)
501 unsubscribe()
502​
503 expect(results.length).toBe(2)
504 expect(results[0]).toMatchObject({ status: 'success', data: 'placeholder' })
505 expect(results[1]).toMatchObject({ status: 'success', data: 'data' })
506 })
507​
508 test('should structurally share placeholder data', async () => {
509 const key = queryKey()
510 const observer = new QueryObserver(queryClient, {
511 queryKey: key,
512 enabled: false,
513 queryFn: () => 'data',
514 placeholderData: {},
515 })
516​
517 const firstData = observer.getCurrentResult().data
518​
519 observer.setOptions({ placeholderData: {} })
520​
521 const secondData = observer.getCurrentResult().data
522​
523 expect(firstData).toBe(secondData)
524 })
525​
526 test('the retrier should not throw an error when reject if the retrier is already resolved', async () => {
527 const key = queryKey()
528 let count = 0
529​
530 const observer = new QueryObserver(queryClient, {
531 queryKey: key,
532 queryFn: () => {
533 count++
534 return Promise.reject<unknown>(`reject ${count}`)
535 },
536 retry: 1,
537 retryDelay: 20,
538 })
539​
540 const unsubscribe = observer.subscribe(() => undefined)
541​
542 // Simulate a race condition when an unsubscribe and a retry occur.
543 await sleep(20)
544 unsubscribe()
545​
546 // A second reject is triggered for the retry
547 // but the retryer has already set isResolved to true
548 // so it does nothing and no error is thrown
549​
550 // Should not log an error
551 queryClient.clear()
552 await sleep(40)
553 expect(mockLogger.error).not.toHaveBeenNthCalledWith(1, 'reject 1')
554 })
555​
556 test('should throw an error if enabled option type is not valid', async () => {
557 const key = queryKey()
558​
559 expect(
560 () =>
561 new QueryObserver(queryClient, {
562 queryKey: key,
563 queryFn: () => 'data',
564 //@ts-expect-error
565 enabled: null,
566 }),
567 ).toThrowError('Expected enabled to be a boolean')
568 })
569​
570 test('getCurrentQuery should return the current query', async () => {
571 const key = queryKey()
572​
573 const observer = new QueryObserver(queryClient, {
574 queryKey: key,
575 queryFn: () => 'data',
576 })
577​
578 expect(observer.getCurrentQuery().queryKey).toEqual(key)
579 })
580​
581 test('should throw an error if throwOnError option is true', async () => {
582 const key = queryKey()
583​
584 const observer = new QueryObserver(queryClient, {
585 queryKey: key,
586 queryFn: () => Promise.reject<unknown>('error'),
587 retry: false,
588 })
589​
590 let error: string | null = null
591 try {
592 await observer.refetch({ throwOnError: true })
593 } catch (err) {
594 error = err as string
595 }
596​
597 expect(error).toEqual('error')
598 })
599​
600 test('should not refetch in background if refetchIntervalInBackground is false', async () => {
601 const key = queryKey()
602 const queryFn = jest.fn<string, unknown[]>().mockReturnValue('data')
603​
604 focusManager.setFocused(false)
605 const observer = new QueryObserver(queryClient, {
606 queryKey: key,
607 queryFn,
608 refetchIntervalInBackground: false,
609 refetchInterval: 10,
610 })
611​
612 const unsubscribe = observer.subscribe(() => undefined)
613 await sleep(30)
614​
615 expect(queryFn).toHaveBeenCalledTimes(1)
616​
617 // Clean-up
618 unsubscribe()
619 focusManager.setFocused(true)
620 })
621​
622 test('should not use replaceEqualDeep for select value when structuralSharing option is true', async () => {
623 const key = queryKey()
624​
625 const data = { value: 'data' }
626 const selectedData = { value: 'data' }
627​
628 const observer = new QueryObserver(queryClient, {
629 queryKey: key,
630 queryFn: () => data,
631 select: () => data,
632 })
633​
634 const unsubscribe = observer.subscribe(() => undefined)
635​
636 await sleep(10)
637 expect(observer.getCurrentResult().data).toBe(data)
638​
639 observer.setOptions({
640 queryKey: key,
641 queryFn: () => data,
642 structuralSharing: false,
643 select: () => selectedData,
644 })
645​
646 await observer.refetch()
647 expect(observer.getCurrentResult().data).toBe(selectedData)
648​
649 unsubscribe()
650 })
651​
652 test('should prefer isDataEqual to structuralSharing', async () => {
653 const key = queryKey()
654​
655 const data = { value: 'data' }
656 const newData = { value: 'data' }
657​
658 const observer = new QueryObserver(queryClient, {
659 queryKey: key,
660 queryFn: () => data,
661 })
662​
663 const unsubscribe = observer.subscribe(() => undefined)
664​
665 await sleep(10)
666 expect(observer.getCurrentResult().data).toBe(data)
667​
668 observer.setOptions({
669 queryKey: key,
670 queryFn: () => newData,
671 isDataEqual: () => true,
672 structuralSharing: false,
673 })
674​
675 await observer.refetch()
676 expect(observer.getCurrentResult().data).toBe(data)
677​
678 unsubscribe()
679 })
680​
681 test('select function error using placeholderdata should log an error', () => {
682 const key = queryKey()
683​
684 new QueryObserver(queryClient, {
685 queryKey: key,
686 queryFn: () => 'data',
687 placeholderData: 'placeholderdata',
688 select: () => {
689 throw new Error('error')
690 },
691 })
692​
693 expect(mockLogger.error).toHaveBeenNthCalledWith(2, new Error('error'))
694 })
695​
696 test('should not use replaceEqualDeep for select value when structuralSharing option is true and placeholderdata is defined', () => {
697 const key = queryKey()
698​
699 const data = { value: 'data' }
700 const selectedData1 = { value: 'data' }
701 const selectedData2 = { value: 'data' }
702 const placeholderData1 = { value: 'data' }
703 const placeholderData2 = { value: 'data' }
704​
705 const observer = new QueryObserver(queryClient, {
706 queryKey: key,
707 queryFn: () => data,
708 select: () => data,
709 })
710​
711 observer.setOptions({
712 queryKey: key,
713 queryFn: () => data,
714 select: () => {
715 return selectedData1
716 },
717 placeholderData: placeholderData1,
718 })
719​
720 observer.setOptions({
721 queryKey: key,
722 queryFn: () => data,
723 select: () => {
724 return selectedData2
725 },
726 placeholderData: placeholderData2,
727 structuralSharing: false,
728 })
729​
730 expect(observer.getCurrentResult().data).toBe(selectedData2)
731 })
732​
733 test('should not use an undefined value returned by select as placeholderdata', () => {
734 const key = queryKey()
735​
736 const data = { value: 'data' }
737 const selectedData = { value: 'data' }
738 const placeholderData1 = { value: 'data' }
739 const placeholderData2 = { value: 'data' }
740​
741 const observer = new QueryObserver(queryClient, {
742 queryKey: key,
743 queryFn: () => data,
744 select: () => data,
745 })
746​
747 observer.setOptions({
748 queryKey: key,
749 queryFn: () => data,
750 select: () => {
751 return selectedData
752 },
753 placeholderData: placeholderData1,
754 })
755​
756 expect(observer.getCurrentResult().isPlaceholderData).toBe(true)
757​
758 observer.setOptions({
759 queryKey: key,
760 queryFn: () => data,
761 //@ts-expect-error
762 select: () => undefined,
763 placeholderData: placeholderData2,
764 })
765​
766 expect(observer.getCurrentResult().isPlaceholderData).toBe(false)
767 })
768​
769 test('updateResult should not notify cache listeners if cache option is false', async () => {
770 const key = queryKey()
771​
772 const data1 = { value: 'data 1' }
773 const data2 = { value: 'data 2' }
774​
775 await queryClient.prefetchQuery(key, () => data1)
776 const observer = new QueryObserver(queryClient, {
777 queryKey: key,
778 })
779 await queryClient.prefetchQuery(key, () => data2)
780​
781 const spy = jest.fn()
782 const unsubscribe = queryClient.getQueryCache().subscribe(spy)
783 observer.updateResult({ cache: false })
784​
785 expect(spy).toHaveBeenCalledTimes(0)
786​
787 unsubscribe()
788 })
789​
790 test('should not notify observer when the stale timeout expires and the current result is stale', async () => {
791 const key = queryKey()
792 const queryFn = () => 'data'
793​
794 await queryClient.prefetchQuery(key, queryFn)
795 const observer = new QueryObserver(queryClient, {
796 queryKey: key,
797 queryFn,
798 staleTime: 20,
799 })
800​
801 const spy = jest.fn()
802 const unsubscribe = observer.subscribe(spy)
803 await queryClient.refetchQueries(key)
804 await sleep(10)
805​
806 // Force isStale to true
807 // because no use case has been found to reproduce this condition
808 // @ts-ignore
809 observer['currentResult'].isStale = true
810 spy.mockReset()
811 await sleep(30)
812 expect(spy).not.toHaveBeenCalled()
813​
814 unsubscribe()
815 })
816​
817 test('setOptions should notify cache listeners', async () => {
818 const key = queryKey()
819​
820 const observer = new QueryObserver(queryClient, {
821 queryKey: key,
822 })
823​
824 const spy = jest.fn()
825 const unsubscribe = queryClient.getQueryCache().subscribe(spy)
826 observer.setOptions({ enabled: false })
827​
828 expect(spy).toHaveBeenCalledTimes(1)
829 expect(spy).toHaveBeenCalledWith(
830 expect.objectContaining({ type: 'observerOptionsUpdated' }),
831 )
832​
833 unsubscribe()
834 })
835})