|
| 1 | +import { beforeEach, describe, expect, it } from 'vitest' |
| 2 | +import { QueryClient, onlineManager } from '@tanstack/query-core' |
| 3 | +import { TanstackQueryDevtoolsPanel } from '..' |
| 4 | + |
| 5 | +describe('TanstackQueryDevtoolsPanel', () => { |
| 6 | + let devtools: TanstackQueryDevtoolsPanel |
| 7 | + |
| 8 | + beforeEach(() => { |
| 9 | + devtools = new TanstackQueryDevtoolsPanel({ |
| 10 | + client: new QueryClient(), |
| 11 | + queryFlavor: 'TanStack Query', |
| 12 | + version: '5', |
| 13 | + onlineManager, |
| 14 | + }) |
| 15 | + }) |
| 16 | + |
| 17 | + describe('mount', () => { |
| 18 | + it('should mount devtools to the provided element', () => { |
| 19 | + const el = document.createElement('div') |
| 20 | + |
| 21 | + expect(() => devtools.mount(el)).not.toThrow() |
| 22 | + |
| 23 | + devtools.unmount() |
| 24 | + }) |
| 25 | + |
| 26 | + it('should throw if mount is called twice without unmount', () => { |
| 27 | + const el = document.createElement('div') |
| 28 | + devtools.mount(el) |
| 29 | + |
| 30 | + expect(() => devtools.mount(el)).toThrow('Devtools is already mounted') |
| 31 | + |
| 32 | + devtools.unmount() |
| 33 | + }) |
| 34 | + }) |
| 35 | + |
| 36 | + describe('unmount', () => { |
| 37 | + it('should unmount devtools and allow remounting', () => { |
| 38 | + const el = document.createElement('div') |
| 39 | + devtools.mount(el) |
| 40 | + |
| 41 | + expect(() => devtools.unmount()).not.toThrow() |
| 42 | + expect(() => devtools.mount(el)).not.toThrow() |
| 43 | + |
| 44 | + devtools.unmount() |
| 45 | + }) |
| 46 | + |
| 47 | + it('should throw if unmount is called before mount', () => { |
| 48 | + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') |
| 49 | + }) |
| 50 | + |
| 51 | + it('should throw if unmount is called twice', () => { |
| 52 | + const el = document.createElement('div') |
| 53 | + devtools.mount(el) |
| 54 | + devtools.unmount() |
| 55 | + |
| 56 | + expect(() => devtools.unmount()).toThrow('Devtools is not mounted') |
| 57 | + }) |
| 58 | + }) |
| 59 | +}) |
0 commit comments