Skip to content

Commit

Permalink
Editor: Refactor PostTypeSupportCheck test to use RTL (#44872)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mamaduka authored Oct 11, 2022
1 parent de4f449 commit f23e051
Showing 1 changed file with 12 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { create } from 'react-test-renderer';
import { render } from '@testing-library/react';

/**
* Internal dependencies
Expand All @@ -10,27 +10,26 @@ import { PostTypeSupportCheck } from '../';

describe( 'PostTypeSupportCheck', () => {
it( 'renders its children when post type is not known', () => {
let postType;
const tree = create(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
const { container } = render(
<PostTypeSupportCheck postType={ undefined } supportKeys="title">
Supported
</PostTypeSupportCheck>
);

expect( tree.toJSON() ).toBe( 'Supported' );
expect( container ).toHaveTextContent( 'Supported' );
} );

it( 'does not render its children when post type is known and not supports', () => {
const postType = {
supports: {},
};
const tree = create(
const { container } = render(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
Supported
</PostTypeSupportCheck>
);

expect( tree.toJSON() ).toBe( null );
expect( container ).not.toHaveTextContent( 'Supported' );
} );

it( 'renders its children when post type is known and supports', () => {
Expand All @@ -39,13 +38,13 @@ describe( 'PostTypeSupportCheck', () => {
title: true,
},
};
const tree = create(
const { container } = render(
<PostTypeSupportCheck postType={ postType } supportKeys="title">
Supported
</PostTypeSupportCheck>
);

expect( tree.toJSON() ).toBe( 'Supported' );
expect( container ).toHaveTextContent( 'Supported' );
} );

it( 'renders its children if some of keys supported', () => {
Expand All @@ -54,7 +53,7 @@ describe( 'PostTypeSupportCheck', () => {
title: true,
},
};
const tree = create(
const { container } = render(
<PostTypeSupportCheck
postType={ postType }
supportKeys={ [ 'title', 'thumbnail' ] }
Expand All @@ -63,14 +62,14 @@ describe( 'PostTypeSupportCheck', () => {
</PostTypeSupportCheck>
);

expect( tree.toJSON() ).toBe( 'Supported' );
expect( container ).toHaveTextContent( 'Supported' );
} );

it( 'does not render its children if none of keys supported', () => {
const postType = {
supports: {},
};
const tree = create(
const { container } = render(
<PostTypeSupportCheck
postType={ postType }
supportKeys={ [ 'title', 'thumbnail' ] }
Expand All @@ -79,6 +78,6 @@ describe( 'PostTypeSupportCheck', () => {
</PostTypeSupportCheck>
);

expect( tree.toJSON() ).toBe( null );
expect( container ).not.toHaveTextContent( 'Supported' );
} );
} );

0 comments on commit f23e051

Please sign in to comment.