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

Convert some enzyme tests that involve HOCs to react-test-renderer (align.js) #7752

Merged
Merged
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
26 changes: 11 additions & 15 deletions editor/hooks/test/align.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/**
* External dependencies
*/
import { mount } from 'enzyme';
import { noop } from 'lodash';
import renderer from 'react-test-renderer';

/**
* WordPress dependencies
Expand Down Expand Up @@ -112,20 +112,18 @@ describe( 'align', () => {
<div { ...wrapperProps } />
) );

const wrapper = mount(
const wrapper = renderer.create(
<EnhancedComponent
name="core/foo"
attributes={ {} }
isSelected
/>
);

expect( wrapper.children() ).toHaveLength( 1 );
// when there's only one child, `rendered` in the tree is an object not an array.
expect( wrapper.toTree().rendered ).toBeInstanceOf( Object );
} );

// Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs.
// eslint-disable-next-line jest/no-disabled-tests
it.skip( 'should render toolbar controls if valid alignments', () => {
it( 'should render toolbar controls if valid alignments', () => {
registerBlockType( 'core/foo', {
...blockSettings,
supports: {
Expand All @@ -138,15 +136,14 @@ describe( 'align', () => {
<div { ...wrapperProps } />
) );

const wrapper = mount(
const wrapper = renderer.create(
<EnhancedComponent
name="core/foo"
attributes={ {} }
isSelected
/>
);

expect( wrapper.children() ).toHaveLength( 2 );
expect( wrapper.toTree().rendered ).toHaveLength( 2 );
} );
} );

Expand All @@ -164,7 +161,7 @@ describe( 'align', () => {
<div { ...wrapperProps } />
) );

const wrapper = mount(
const wrapper = renderer.create(
<EnhancedComponent
block={ {
name: 'core/foo',
Expand All @@ -174,8 +171,7 @@ describe( 'align', () => {
} }
/>
);

expect( wrapper.childAt( 0 ).prop( 'wrapperProps' ) ).toEqual( {
expect( wrapper.toTree().rendered.props.wrapperProps ).toEqual( {
'data-align': 'left',
} );
} );
Expand All @@ -193,7 +189,7 @@ describe( 'align', () => {
<div { ...wrapperProps } />
) );

const wrapper = mount(
const wrapper = renderer.create(
<EnhancedComponent
block={ {
name: 'core/foo',
Expand All @@ -204,7 +200,7 @@ describe( 'align', () => {
/>
);

expect( wrapper.childAt( 0 ).prop( 'wrapperProps' ) ).toBeUndefined();
expect( wrapper.toTree().props.wrapperProps ).toBeUndefined();
} );
} );

Expand Down