Skip to content

Commit

Permalink
Components: Refactor TreeGrid RovingTabIndexItem tests to RTL (#44821)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Oct 10, 2022
1 parent f8503f7 commit 82eccd4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RovingTabIndexItem allows another component to be specified as the rendered component using the \`as\` prop 1`] = `
<button
onFocus={[Function]}
/>
<div>
<button />
</div>
`;

exports[`RovingTabIndexItem allows children to be declared using a child render function as an alternative to \`as\` 1`] = `
<button
className="my-button"
onFocus={[Function]}
>
Click Me!
</button>
<div>
<button
class="my-button"
>
Click Me!
</button>
</div>
`;

exports[`RovingTabIndexItem forwards props to the \`as\` component 1`] = `
<button
className="my-button"
onFocus={[Function]}
>
Click Me!
</button>
<div>
<button
class="my-button"
>
Click Me!
</button>
</div>
`;
16 changes: 8 additions & 8 deletions packages/components/src/tree-grid/test/roving-tab-index-item.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import TestRenderer from 'react-test-renderer';
import { render } from '@testing-library/react';

/**
* WordPress dependencies
Expand All @@ -21,35 +21,35 @@ const TestButton = forwardRef( ( { ...props }, ref ) => (
describe( 'RovingTabIndexItem', () => {
it( 'requires RovingTabIndex to be declared as a parent component somewhere in the component hierarchy', () => {
expect( () =>
TestRenderer.create( <RovingTabIndexItem as={ TestButton } /> )
render( <RovingTabIndexItem as={ TestButton } /> )
).toThrow();
expect( console ).toHaveErrored();
} );

it( 'allows another component to be specified as the rendered component using the `as` prop', () => {
const renderer = TestRenderer.create(
const { container } = render(
<RovingTabIndex>
<RovingTabIndexItem as={ TestButton } />
</RovingTabIndex>
);

expect( renderer.toJSON() ).toMatchSnapshot();
expect( container ).toMatchSnapshot();
} );

it( 'forwards props to the `as` component', () => {
const renderer = TestRenderer.create(
const { container } = render(
<RovingTabIndex>
<RovingTabIndexItem as={ TestButton } className="my-button">
Click Me!
</RovingTabIndexItem>
</RovingTabIndex>
);

expect( renderer.toJSON() ).toMatchSnapshot();
expect( container ).toMatchSnapshot();
} );

it( 'allows children to be declared using a child render function as an alternative to `as`', () => {
const renderer = TestRenderer.create(
const { container } = render(
<RovingTabIndex>
<RovingTabIndexItem>
{ ( props ) => (
Expand All @@ -61,6 +61,6 @@ describe( 'RovingTabIndexItem', () => {
</RovingTabIndex>
);

expect( renderer.toJSON() ).toMatchSnapshot();
expect( container ).toMatchSnapshot();
} );
} );

0 comments on commit 82eccd4

Please sign in to comment.