From 20381c142eca4634ae3774a45382a1baaec3a337 Mon Sep 17 00:00:00 2001 From: siloneco Date: Fri, 10 Nov 2023 07:05:45 +0000 Subject: [PATCH] feat: add test for checking trigger works fine --- src/components/ui/Popover/index.test.tsx | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/ui/Popover/index.test.tsx b/src/components/ui/Popover/index.test.tsx index fc74f72..0582df4 100644 --- a/src/components/ui/Popover/index.test.tsx +++ b/src/components/ui/Popover/index.test.tsx @@ -1,4 +1,5 @@ import { render } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; import '@testing-library/jest-dom'; import { Popover, PopoverTrigger, PopoverContent } from '.'; @@ -31,15 +32,25 @@ describe('test ui/Popover', () => { ); }); - it('not renders content by default', () => { + it('check trigger works correctly', async () => { + const trigger = 'Trigger'; const content = 'Content'; const screen = render( - Trigger + {trigger} {content} ); + // closed by default + expect(() => screen.getByText(content)).toThrow(); + + // open on trigger clicked + await userEvent.click(screen.getByText(trigger)); + expect(screen.getByText(content)).toBeInTheDocument(); + + // close on trigger clicked + await userEvent.click(screen.getByText(trigger)); expect(() => screen.getByText(content)).toThrow(); }); });