import { cleanup, fireEvent, render, screen, waitForElementToBeRemoved, } from '@testing-library/react'; import { expect } from 'chai'; import React from 'react'; import { ToastArea, ToastVariant, useToast } from './use-toast'; const OpenToastButton = ({ namespace, id, title, variant, timeout, body, }: { namespace: string; variant: ToastVariant; id: string; title: string; timeout?: number; body?: string; }) => { const { openToast } = useToast(namespace); return ( ); }; const CloseToastButton = ({ namespace, id, }: { namespace: string; id: string; }) => { const { closeToast } = useToast(namespace); return ( ); }; describe('useToast', function () { afterEach(cleanup); it('opens and closes a toast', async function () { render( ); fireEvent.click(screen.getByText('Open Toast')); await screen.findByText('My Toast'); screen.getByText('Toast body'); fireEvent.click(screen.getByText('Close Toast')); expect(screen.queryByText('My Toast')).to.not.exist; }); describe('with timeout', function () { it('closes a toast after timeout expires', async function () { render( ); fireEvent.click(screen.getByText('Open Toast')); await screen.findByText('My Toast'); await waitForElementToBeRemoved(() => { return screen.queryByText('My Toast'); }); expect(screen.queryByText('My Toast')).to.not.exist; }); }); });