diff --git a/packages/components/src/button/test/index.js b/packages/components/src/button/test/index.js index 9d2b9f5383cea..a7ebaf7314a32 100644 --- a/packages/components/src/button/test/index.js +++ b/packages/components/src/button/test/index.js @@ -1,8 +1,8 @@ /** * External dependencies */ -import { shallow } from 'enzyme'; -import TestUtils from 'react-dom/test-utils'; +import { render, screen } from '@testing-library/react'; + /** * WordPress dependencies */ @@ -12,172 +12,188 @@ import { plusCircle } from '@wordpress/icons'; /** * Internal dependencies */ -import ButtonWithForwardedRef, { Button } from '../'; -import { VisuallyHidden } from '../../visually-hidden'; +import Button from '../'; + +jest.mock( '../../icon', () => () =>
); describe( 'Button', () => { describe( 'basic rendering', () => { it( 'should render a button element with only one class', () => { - const button = shallow( - ).find( 'Tooltip' ); + ); - expect( buttonTooltip.prop( 'text' ) ).toBe( 'Description text' ); + expect( + screen.getByRole( 'button', { + description: 'Description text', + } ) + ).toBeVisible(); } ); - it( 'should allow tooltip disable', () => { - const iconButton = shallow( + it( 'should allow tooltip disable', async () => { + render( - ).find( 'button' ); - expect( iconButton.name() ).toBe( 'button' ); + ); + + expect( screen.queryByText( 'WordPress' ) ).not.toBeInTheDocument(); + + await screen.getByRole( 'button', { name: 'WordPress' } ).focus(); + + expect( screen.queryByText( 'WordPress' ) ).not.toBeInTheDocument(); } ); - it( 'should force showing the tooltip even if icon and children defined', () => { - const iconButton = shallow( + it( 'should force showing the tooltip even if icon and children defined', async () => { + render( - ).find( 'Tooltip' ); - expect( iconButton.name() ).toBe( 'Tooltip' ); + ); + + expect( screen.queryByText( 'WordPress' ) ).not.toBeInTheDocument(); + + await screen.getByRole( 'button', { name: 'WordPress' } ).focus(); + + expect( screen.getByText( 'WordPress' ) ).toBeVisible(); } ); } ); describe( 'with href property', () => { it( 'should render a link instead of a button with href prop', () => { - const button = shallow( -