|
1 | 1 | import * as React from 'react' |
2 | 2 | import { fireEvent, screen, waitFor, act } from '@testing-library/react' |
3 | 3 | import '@testing-library/jest-dom' |
4 | | -import { useQuery } from '@tanstack/react-query' |
| 4 | +import { useQuery, onlineManager } from '@tanstack/react-query' |
5 | 5 | import { defaultPanelSize, sortFns } from '../utils' |
6 | 6 | import { |
7 | 7 | getByTextContent, |
@@ -478,6 +478,31 @@ describe('ReactQueryDevtools', () => { |
478 | 478 | expect(count).toBe(2) |
479 | 479 | }) |
480 | 480 |
|
| 481 | + it('should inform onlineManager when offline mode is simulated', () => { |
| 482 | + const { queryClient } = createQueryClient() |
| 483 | + const online: Array<boolean> = [] |
| 484 | + |
| 485 | + const unsubscribe = onlineManager.subscribe(() => { |
| 486 | + online.push(onlineManager.isOnline()) |
| 487 | + }) |
| 488 | + |
| 489 | + renderWithClient(queryClient, <div />, { |
| 490 | + initialIsOpen: true, |
| 491 | + }) |
| 492 | + |
| 493 | + fireEvent.click( |
| 494 | + screen.getByRole('button', { name: /mock offline behavior/i }), |
| 495 | + ) |
| 496 | + |
| 497 | + fireEvent.click( |
| 498 | + screen.getByRole('button', { name: /restore offline mock/i }), |
| 499 | + ) |
| 500 | + |
| 501 | + expect(online).toStrictEqual([false, true]) |
| 502 | + |
| 503 | + unsubscribe() |
| 504 | + }) |
| 505 | + |
481 | 506 | it('should sort the queries according to the sorting filter', async () => { |
482 | 507 | const { queryClient, queryCache } = createQueryClient() |
483 | 508 |
|
|
0 commit comments