Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jan 23, 2024
1 parent ad3b6f5 commit 03404d4
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/components/src/button/test/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,45 @@ describe( 'Button', () => {
).not.toBeInTheDocument();
} );

it( 'should not trash the rendered HTML elements when toggling between showing and not showing a tooltip', async () => {
const user = userEvent.setup();

const { rerender } = render(
<Button label="Button label">Test button</Button>
);

const button = screen.getByRole( 'button', {
name: 'Button label',
} );

expect( button ).toBeVisible();

await user.tab();

expect( button ).toHaveFocus();

// Re-render the button, but this time change the settings so that it
// shows a tooltip.
rerender(
<Button label="Button label" showTooltip>
Test button
</Button>
);

// The same button element that we referenced before should still be
// in the document.
expect( button ).toBeVisible();
expect( button ).toHaveFocus();

// Re-render the button, but stop showing a tooltip.
rerender( <Button label="Button label">Test button</Button> );

// The same button element that we referenced before should still be
// in the document.
expect( button ).toBeVisible();
expect( button ).toHaveFocus();
} );

it( 'should add a disabled prop to the button', () => {
render( <Button disabled /> );

Expand Down

0 comments on commit 03404d4

Please sign in to comment.