Skip to content

Commit

Permalink
Switch test away from enzyme.mount usage. (#7784)
Browse files Browse the repository at this point in the history
Switches ‘should open menu on arrow down’ test from rendering using `enzyme.mount` to rendering using `React.TestUtils`.
  • Loading branch information
nerrad authored and gziolo committed Jul 12, 2018
1 parent a4b1945 commit b204c40
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions components/dropdown-menu/test/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
/**
* External dependencies
*/
import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';
import TestUtils from 'react-dom/test-utils';

/**
* WordPress dependencies
*/
import { DOWN } from '@wordpress/keycodes';
import { Component } from '@wordpress/element';

/**
* Internal dependencies
*/
import DropdownMenu from '../';
import Popover from '../../popover';

describe( 'DropdownMenu', () => {
let controls;
Expand Down Expand Up @@ -54,16 +57,29 @@ describe( 'DropdownMenu', () => {
} );

it( 'should open menu on arrow down', () => {
const wrapper = mount( <DropdownMenu controls={ controls } /> );

// needed because TestUtils.renderIntoDocument returns null for stateless
// components
class Menu extends Component {
render() {
return <DropdownMenu { ...this.props } />;
}
}
const wrapper = TestUtils.renderIntoDocument( <Menu controls={ controls } /> );
const buttonElement = TestUtils.findRenderedDOMComponentWithClass(
wrapper,
'components-dropdown-menu__toggle'
);
// Close menu by keyup
wrapper.find( 'button.components-dropdown-menu__toggle' ).simulate( 'keydown', {
stopPropagation: () => {},
preventDefault: () => {},
keyCode: DOWN,
} );
TestUtils.Simulate.keyDown(
buttonElement,
{
stopPropagation: () => {},
preventDefault: () => {},
keyCode: DOWN,
}
);

expect( wrapper.find( 'Popover' ) ).toHaveLength( 1 );
expect( TestUtils.scryRenderedComponentsWithType( wrapper, Popover ) ).toHaveLength( 1 );
} );
} );
} );

0 comments on commit b204c40

Please sign in to comment.