From 3315d327b48d1ecce64fda419069ee485fd84ce7 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Sun, 8 Jul 2018 12:28:13 -0400 Subject: [PATCH] Switch test away from using `enzyme.mount` 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. --- editor/components/url-input/test/button.js | 26 ++++++++++++++++------ 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/editor/components/url-input/test/button.js b/editor/components/url-input/test/button.js index 19bfc72c36b9c..32590d0218af2 100644 --- a/editor/components/url-input/test/button.js +++ b/editor/components/url-input/test/button.js @@ -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 @@ -57,11 +59,21 @@ describe( 'UrlInputButton', () => { expect( wrapper.state().expanded ).toBe( false ); } ); it( 'should close the form when user submits it', () => { - const wrapper = mount( ); - 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( ); + 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 */ } ); } );