Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components: Refactor TreeGrid's RovingTabIndexItem tests to RTL #44821

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
`;
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();
} );
} );