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( 'button' );
- expect( button.hasClass( 'components-button' ) ).toBe( true );
- expect( button.hasClass( 'is-large' ) ).toBe( false );
- expect( button.hasClass( 'is-primary' ) ).toBe( false );
- expect( button.hasClass( 'is-pressed' ) ).toBe( false );
- expect( button.prop( 'disabled' ) ).toBeUndefined();
- expect( button.prop( 'aria-disabled' ) ).toBeUndefined();
- expect( button.prop( 'type' ) ).toBe( 'button' );
- expect( button.type() ).toBe( 'button' );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).toHaveClass( 'components-button' );
+ expect( button ).not.toHaveClass( 'is-large' );
+ expect( button ).not.toHaveClass( 'is-primary' );
+ expect( button ).not.toHaveClass( 'is-pressed' );
+ expect( button ).not.toHaveAttribute( 'disabled' );
+ expect( button ).not.toHaveAttribute( 'aria-disabled' );
+ expect( button ).toHaveAttribute( 'type', 'button' );
} );
it( 'should render a button element with is-primary class', () => {
- const button = shallow( ).find(
- 'button'
- );
- expect( button.hasClass( 'is-large' ) ).toBe( false );
- expect( button.hasClass( 'is-primary' ) ).toBe( true );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).not.toHaveClass( 'is-large' );
+ expect( button ).toHaveClass( 'is-primary' );
} );
it( 'should render a button element with is-secondary and is-small class', () => {
- const button = shallow(
-
- ).find( 'button' );
- expect( button.hasClass( 'is-secondary' ) ).toBe( true );
- expect( button.hasClass( 'is-large' ) ).toBe( false );
- expect( button.hasClass( 'is-small' ) ).toBe( true );
- expect( button.hasClass( 'is-primary' ) ).toBe( false );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).toHaveClass( 'is-secondary' );
+ expect( button ).not.toHaveClass( 'is-large' );
+ expect( button ).toHaveClass( 'is-small' );
+ expect( button ).not.toHaveClass( 'is-primary' );
} );
it( 'should render a button element with is-tertiary class', () => {
- const button = shallow( ).find(
- 'button'
- );
- expect( button.hasClass( 'is-large' ) ).toBe( false );
- expect( button.hasClass( 'is-primary' ) ).toBe( false );
- expect( button.hasClass( 'is-secondary' ) ).toBe( false );
- expect( button.hasClass( 'is-tertiary' ) ).toBe( true );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).not.toHaveClass( 'is-large' );
+ expect( button ).not.toHaveClass( 'is-primary' );
+ expect( button ).not.toHaveClass( 'is-secondary' );
+ expect( button ).toHaveClass( 'is-tertiary' );
} );
it( 'should render a button element with is-link class', () => {
- const button = shallow( ).find(
- 'button'
- );
- expect( button.hasClass( 'is-primary' ) ).toBe( false );
- expect( button.hasClass( 'is-secondary' ) ).toBe( false );
- expect( button.hasClass( 'is-tertiary' ) ).toBe( false );
- expect( button.hasClass( 'is-link' ) ).toBe( true );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).not.toHaveClass( 'is-primary' );
+ expect( button ).not.toHaveClass( 'is-secondary' );
+ expect( button ).not.toHaveClass( 'is-tertiary' );
+ expect( button ).toHaveClass( 'is-link' );
} );
it( 'should render a button element with is-pressed without button class', () => {
- const button = shallow( ).find( 'button' );
- expect( button.hasClass( 'is-pressed' ) ).toBe( true );
+ render( );
+
+ expect( screen.getByRole( 'button' ) ).toHaveClass( 'is-pressed' );
} );
it( 'should add a disabled prop to the button', () => {
- const button = shallow( ).find( 'button' );
- expect( button.prop( 'disabled' ) ).toBe( true );
+ render( );
+
+ expect( screen.getByRole( 'button' ) ).toHaveAttribute(
+ 'disabled'
+ );
} );
it( 'should add only aria-disabled attribute when disabled and isFocusable are true', () => {
- const button = shallow(
-
- ).find( 'button' );
- expect( button.prop( 'disabled' ) ).toBe( false );
- expect( button.prop( 'aria-disabled' ) ).toBe( true );
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).not.toHaveAttribute( 'disabled' );
+ expect( button ).toHaveAttribute( 'aria-disabled' );
} );
- it( 'should not poss the prop target into the element', () => {
- const button = shallow( ).find(
- 'button'
+ it( 'should not pass the prop target into the element', () => {
+ render( );
+
+ expect( screen.getByRole( 'button' ) ).not.toHaveAttribute(
+ 'target'
);
- expect( button.prop( 'target' ) ).toBeUndefined();
} );
it( 'should render with an additional className', () => {
- const button = shallow( ).find(
- 'button'
- );
+ render( );
- expect( button.hasClass( 'gutenberg' ) ).toBe( true );
+ expect( screen.getByRole( 'button' ) ).toHaveClass( 'gutenberg' );
} );
- it( 'should render and additional WordPress prop of value awesome', () => {
- const button = shallow( ).find(
- 'button'
- );
+ it( 'should render an additional WordPress prop of value awesome', () => {
+ render( );
- expect( button.prop( 'WordPress' ) ).toBe( 'awesome' );
+ expect( console ).toHaveErrored();
+ expect( screen.getByRole( 'button' ) ).toHaveAttribute(
+ 'wordpress',
+ 'awesome'
+ );
} );
it( 'should render an icon button', () => {
- const iconButton = shallow( ).find(
- 'button'
- );
- expect( iconButton.hasClass( 'has-icon' ) ).toBe( true );
- expect( iconButton.prop( 'aria-label' ) ).toBeUndefined();
+ render( );
+ const button = screen.getByRole( 'button' );
+
+ expect( button ).toHaveClass( 'has-icon' );
+ expect( button ).not.toHaveAttribute( 'aria-label' );
} );
it( 'should render a Dashicon component matching the wordpress icon', () => {
- const iconButton = shallow( ).find(
- 'button'
+ render( );
+
+ expect( screen.getByRole( 'button' ) ).toContainElement(
+ screen.getByTestId( 'test-icon' )
);
- expect( iconButton.find( 'Icon' ).dive() ).not.toBeNull();
} );
it( 'should render child elements and icon', () => {
- const iconButton = shallow(
+ render(