UNPKG

@navinc/base-react-components

Version:
37 lines 1.51 kB
import { jsx as _jsx } from "react/jsx-runtime"; import { beforeEach, describe, expect, it, vi } from 'vitest'; import { renderWithContext } from './tests/with-app-context.js'; import { screen } from '@testing-library/react'; import { AnimateHeight } from './animate-height.js'; describe('AnimateHeight', () => { let disconnect; let observe; beforeEach(() => { disconnect = vi.fn(); observe = vi.fn(); global.ResizeObserver = class { constructor() { this.disconnect = disconnect; this.observe = observe; } }; }); it('animates the height of the container when the content changes', () => { renderWithContext(_jsx(AnimateHeight, { children: "Content" })); expect(screen.getByText(/content/i)).toBeInTheDocument(); }); it('listens for window resizes and DOM mutations', () => { vi.spyOn(global, 'addEventListener'); renderWithContext(_jsx(AnimateHeight, { children: "Content" })); expect(observe).toHaveBeenCalled(); expect(global.addEventListener).toHaveBeenCalled(); }); it('cleans up after itself', () => { vi.spyOn(global, 'removeEventListener'); const { unmount } = renderWithContext(_jsx(AnimateHeight, { children: "Content" })); unmount(); expect(disconnect).toHaveBeenCalled(); expect(global.removeEventListener).toHaveBeenCalled(); }); }); //# sourceMappingURL=animate-height.spec.js.map