Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Aug 3, 2022
1 parent dabc232 commit 6d4e076
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion packages/components/src/popover/test/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { act, render } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';

/**
* WordPress dependencies
*/
import { useRef } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -44,4 +49,21 @@ describe( 'Popover', () => {

expect( result.container.querySelector( 'span' ) ).toMatchSnapshot();
} );

it( 'should render correctly when anchorRef is provided', () => {
const PopoverWithAnchor = ( args ) => {
const anchorRef = useRef( null );

return (
<div>
<p ref={ anchorRef }>Anchor</p>
<Popover { ...args } anchorRef={ anchorRef } />
</div>
);
};

render( <PopoverWithAnchor>Popover content</PopoverWithAnchor> );

expect( screen.getByText( 'Popover content' ) ).toBeInTheDocument();
} );
} );

0 comments on commit 6d4e076

Please sign in to comment.