-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch tests away from enzyme.mount (#7796)
This switches all tests in `components/higher-order/with-context/test/index.js` from using enzyme.mount to `React.TestRenderer`. 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).
- Loading branch information
Showing
1 changed file
with
34 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,59 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { mount } from 'enzyme'; | ||
import renderer from 'react-test-renderer'; | ||
import PropTypes from 'prop-types'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import withContext from '../'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Component } from '@wordpress/element'; | ||
|
||
class PassContext extends Component { | ||
getChildContext() { | ||
return this.props.value; | ||
} | ||
|
||
render() { | ||
return this.props.children; | ||
} | ||
} | ||
|
||
PassContext.childContextTypes = { | ||
value: PropTypes.any, | ||
settings: PropTypes.any, | ||
}; | ||
|
||
describe( 'withContext', () => { | ||
it( 'should return a new component which has context', () => { | ||
const Component = withContext( 'value' )()( ( { value } ) => <div>{ value }</div> ); | ||
const wrapper = mount( | ||
<Component />, | ||
{ context: { value: 'ok' } } | ||
const TestComponent = withContext( 'value' )()( ( { value } ) => <div>{ value }</div> ); | ||
const wrapper = renderer.create( | ||
<PassContext value={ { value: 'ok' } }> | ||
<TestComponent /> | ||
</PassContext> | ||
); | ||
|
||
expect( wrapper.text() ).toBe( 'ok' ); | ||
expect( wrapper.root.findByType( 'div' ).children[ 0 ] ).toBe( 'ok' ); | ||
} ); | ||
|
||
it( 'should allow specifying a context getter mapping', () => { | ||
const Component = withContext( 'settings' )( | ||
const TestComponent = withContext( 'settings' )( | ||
( settings ) => ( { remap: settings.value } ) | ||
)( | ||
( { ignore, remap } ) => <div>{ ignore }{ remap }</div> | ||
); | ||
|
||
const wrapper = mount( | ||
<Component />, | ||
{ context: { settings: { ignore: 'ignore', value: 'ok' } } } | ||
const wrapper = renderer.create( | ||
<PassContext value={ { settings: { ignore: 'ignore', value: 'ok' } } } > | ||
<TestComponent /> | ||
</PassContext> | ||
); | ||
|
||
expect( wrapper.text() ).toBe( 'ok' ); | ||
expect( wrapper.root.findByType( 'div' ).children[ 0 ] ).toBe( 'ok' ); | ||
} ); | ||
} ); |