Skip to content

Commit

Permalink
feat: add test for checking trigger works fine
Browse files Browse the repository at this point in the history
  • Loading branch information
siloneco committed Nov 10, 2023
1 parent 8caa32a commit 20381c1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/components/ui/Popover/index.test.tsx
Original file line number Diff line number Diff line change
@@ -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 '.';
Expand Down Expand Up @@ -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(
<Popover>
<PopoverTrigger>Trigger</PopoverTrigger>
<PopoverTrigger>{trigger}</PopoverTrigger>
<PopoverContent>{content}</PopoverContent>
</Popover>
);

// 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();
});
});

0 comments on commit 20381c1

Please sign in to comment.