Skip to content

Commit

Permalink
Convert some enzyme tests that involve HOCs to react-test-renderer (a…
Browse files Browse the repository at this point in the history
…lign.js) (#7752)
  • Loading branch information
nerrad authored Jul 9, 2018
1 parent e697f72 commit 22ae609
Showing 1 changed file with 11 additions and 15 deletions.
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

0 comments on commit 22ae609

Please sign in to comment.