Skip to content

Commit

Permalink
Switch test away from using enzyme.mount (#7786)
Browse files Browse the repository at this point in the history
This switched the `should close the form when user submits it` from using enzyme.mount to React.TestUtilities.  This is because enzyme does not fully support React 16.3+ (and movement to do so is really slow). This will fix issues with breakage due to the enzyme incompatibility as components receive React 16.3+ features (such as forwardRef usage in #7557). This specific test was the only one to fail in #7557 due to the test involving the EnhancedAutocomplete component that has forwardRef applied on it.
  • Loading branch information
nerrad authored and gziolo committed Jul 12, 2018
1 parent b204c40 commit 96809cb
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions editor/components/url-input/test/button.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/**
* External dependencies
*/
import { shallow, mount } from 'enzyme';
import { shallow } from 'enzyme';
import TestUtils from 'react-dom/test-utils';
import ReactDOM from 'react-dom';

/**
* Internal dependencies
Expand Down Expand Up @@ -57,11 +59,21 @@ describe( 'UrlInputButton', () => {
expect( wrapper.state().expanded ).toBe( false );
} );
it( 'should close the form when user submits it', () => {
const wrapper = mount( <UrlInputButton /> );
clickEditLink( wrapper );
expect( wrapper.state().expanded ).toBe( true );
wrapper.find( 'form' ).simulate( 'submit' );
expect( wrapper.state().expanded ).toBe( false );
wrapper.unmount();
const wrapper = TestUtils.renderIntoDocument( <UrlInputButton /> );
const buttonElement = () => TestUtils.findRenderedDOMComponentWithClass(
wrapper,
'components-toolbar__control'
);
const formElement = () => TestUtils.findRenderedDOMComponentWithTag(
wrapper,
'form'
);
TestUtils.Simulate.click( buttonElement() );
expect( wrapper.state.expanded ).toBe( true );
TestUtils.Simulate.submit( formElement() );
expect( wrapper.state.expanded ).toBe( false );
/* eslint-disable react/no-find-dom-node */
ReactDOM.unmountComponentAtNode( ReactDOM.findDOMNode( wrapper ).parentNode );
/* eslint-enable react/no-find-dom-node */
} );
} );

0 comments on commit 96809cb

Please sign in to comment.