From b3c15507e075993d9ef44f515834b74f0e3e665b Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Mon, 9 Jul 2018 11:26:16 -0400 Subject: [PATCH] Switch tests away from using enzyme.mount This switches all tests in `components/higher-order/with-state/test/index.js` from using enzyme.mount to `React.TestUtils`. 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). --- .../higher-order/with-state/test/index.js | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/components/higher-order/with-state/test/index.js b/components/higher-order/with-state/test/index.js index b9187614a26cbe..89c36403b51f86 100644 --- a/components/higher-order/with-state/test/index.js +++ b/components/higher-order/with-state/test/index.js @@ -1,13 +1,29 @@ /** * External dependencies */ -import { mount } from 'enzyme'; +import TestUtils from 'react-dom/test-utils'; /** * Internal dependencies */ import withState from '../'; +/** + * WordPress dependencies + */ +import { Component } from '@wordpress/element'; + +// this is needed because TestUtils does not accept a stateless component. +// anything run through a HOC ends up as a stateless component. +const getTestComponent = ( WrappedComponent ) => { + class TestComponent extends Component { + render() { + return ; + } + } + return ; +}; + describe( 'withState', () => { it( 'should pass initial state and allow updates', () => { const EnhancedComponent = withState( { count: 0 } )( ( { count, setState } ) => ( @@ -16,10 +32,11 @@ describe( 'withState', () => { ) ); - const wrapper = mount( ); + const wrapper = TestUtils.renderIntoDocument( getTestComponent( EnhancedComponent ) ); + const buttonElement = () => TestUtils.findRenderedDOMComponentWithTag( wrapper, 'button' ); - expect( wrapper.html() ).toBe( '' ); - wrapper.find( 'button' ).simulate( 'click' ); - expect( wrapper.html() ).toBe( '' ); + expect( buttonElement().outerHTML ).toBe( '' ); + TestUtils.Simulate.click( buttonElement() ); + expect( buttonElement().outerHTML ).toBe( '' ); } ); } );