From c314b15a204ee5e4015f8986919313ba20d0eb53 Mon Sep 17 00:00:00 2001 From: Darren Ethier Date: Mon, 9 Jul 2018 20:16:11 -0400 Subject: [PATCH] remove tests from being skipped (#7835) --- components/disabled/test/index.js | 80 +++++++++++++++++-------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/components/disabled/test/index.js b/components/disabled/test/index.js index b12a9e943d82c..647af5d30d1c7 100644 --- a/components/disabled/test/index.js +++ b/components/disabled/test/index.js @@ -1,7 +1,12 @@ /** * External dependencies */ -import { mount } from 'enzyme'; +import TestUtils from 'react-dom/test-utils'; + +/** + * WordPress dependencies + */ +import { Component } from '@wordpress/element'; /** * Internal dependencies @@ -53,13 +58,11 @@ describe( 'Disabled', () => { const Form = () =>
; - // Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs. - // eslint-disable-next-line jest/no-disabled-tests - test.skip( 'will disable all fields', () => { - const wrapper = mount(
); + it( 'will disable all fields', () => { + const wrapper = TestUtils.renderIntoDocument( ); - const input = wrapper.find( 'input' ).getDOMNode(); - const div = wrapper.find( '[contentEditable]' ).getDOMNode(); + const input = TestUtils.findRenderedDOMComponentWithTag( wrapper, 'input' ); + const div = TestUtils.scryRenderedDOMComponentsWithTag( wrapper, 'div' )[ 1 ]; expect( input.hasAttribute( 'disabled' ) ).toBe( true ); expect( div.getAttribute( 'contenteditable' ) ).toBe( 'false' ); @@ -67,23 +70,30 @@ describe( 'Disabled', () => { expect( div.hasAttribute( 'disabled' ) ).toBe( false ); } ); - // Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs. - // eslint-disable-next-line jest/no-disabled-tests - test.skip( 'should cleanly un-disable via reconciliation', () => { + it( 'should cleanly un-disable via reconciliation', () => { // If this test suddenly starts failing, it means React has become // smarter about reusing children into grandfather element when the // parent is dropped, so we'd need to find another way to restore // original form state. - function MaybeDisable( { isDisabled = true } ) { - const element = ; - return isDisabled ? { element } : element; + // Using state for this test for easier manipulation of the child props. + class MaybeDisable extends Component { + constructor() { + super( ...arguments ); + this.state = { isDisabled: true }; + } + + render() { + return this.state.isDisabled ? + : + ; + } } - const wrapper = mount( ); - wrapper.setProps( { isDisabled: false } ); + const wrapper = TestUtils.renderIntoDocument( ); + wrapper.setState( { isDisabled: false } ); - const input = wrapper.find( 'input' ).getDOMNode(); - const div = wrapper.find( '[contentEditable]' ).getDOMNode(); + const input = TestUtils.findRenderedDOMComponentWithTag( wrapper, 'input' ); + const div = TestUtils.findRenderedDOMComponentWithTag( wrapper, 'div' ); expect( input.hasAttribute( 'disabled' ) ).toBe( false ); expect( div.getAttribute( 'contenteditable' ) ).toBe( 'true' ); @@ -100,28 +110,28 @@ describe( 'Disabled', () => { // https://github.com/jsdom/jsdom/issues/639 describe( 'Consumer', () => { - function DisabledStatus() { - return ( -

- - { ( isDisabled ) => isDisabled ? 'Disabled' : 'Not disabled' } - -

- ); + class DisabledStatus extends Component { + render() { + return ( +

+ + { ( isDisabled ) => isDisabled ? 'Disabled' : 'Not disabled' } + +

+ ); + } } - // Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs. - // eslint-disable-next-line jest/no-disabled-tests - test.skip( 'lets components know that they\'re disabled via context', () => { - const wrapper = mount( ); - expect( wrapper.text() ).toBe( 'Disabled' ); + test( 'lets components know that they\'re disabled via context', () => { + const wrapper = TestUtils.renderIntoDocument( ); + const wrapperElement = TestUtils.findRenderedDOMComponentWithTag( wrapper, 'p' ); + expect( wrapperElement.textContent ).toBe( 'Disabled' ); } ); - // Skipped temporarily until Enzyme publishes new version that works with React 16.3.0 APIs. - // eslint-disable-next-line jest/no-disabled-tests - test.skip( 'lets components know that they\'re not disabled via context', () => { - const wrapper = mount( ); - expect( wrapper.text() ).toBe( 'Not disabled' ); + test( 'lets components know that they\'re not disabled via context', () => { + const wrapper = TestUtils.renderIntoDocument( ); + const wrapperElement = TestUtils.findRenderedDOMComponentWithTag( wrapper, 'p' ); + expect( wrapperElement.textContent ).toBe( 'Not disabled' ); } ); } ); } );