import { act, cleanup, waitFor } from '@testing-library/react'; import { render } from '../../../utils/theme-render-wrapper'; import Notification, { showNotif } from './notification'; afterEach(cleanup); describe('', () => { it('should render null when no notification fired', () => { const message = 'hello'; const { debug, queryByText } = render(); }); it('should render notification and hide after timeout', async () => { const message = 'hello'; const timeout = 4000; const { getByText, queryByText } = render(); act(() => showNotif(message, { ms: timeout })); const el = getByText(message); expect(el.innerHTML).toBe(message); await waitFor(async () => await new Promise(r => setTimeout(r, timeout)), { timeout: timeout + 500 }).then(() => expect(queryByText(message)).toBeNull()); }); it('should render a ReactNode inside the notification', async () => { const message = 'HELLO'; const timeout = 4000; const Component = (

HELLO

); const { getByText } = render(); act(() => showNotif(Component, { ms: timeout })); const el = getByText(message); expect(el.innerHTML).toBe(message); }); });