-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components: Implement Button as assigning ref via forwardRef #6527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,20 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { shallow } from 'enzyme'; | ||
import { mount, shallow } from 'enzyme'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { createRef } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Button from '../'; | ||
import ButtonWithForwardedRef, { Button } from '../'; | ||
|
||
// [TEMPORARY]: Only needed so long as Enzyme does not support React.forwardRef | ||
jest.unmock( '../' ); | ||
|
||
describe( 'Button', () => { | ||
describe( 'basic rendering', () => { | ||
|
@@ -93,4 +101,18 @@ describe( 'Button', () => { | |
expect( button.type() ).toBe( 'button' ); | ||
} ); | ||
} ); | ||
|
||
// Disable reason: This test is desirable, but unsupported by Enzyme in | ||
// the current version, as it depends on features new to React in 16.3.0. | ||
// | ||
// eslint-disable-next-line jest/no-disabled-tests | ||
describe.skip( 'ref forwarding', () => { | ||
it( 'should enable access to DOM element', () => { | ||
const ref = createRef(); | ||
|
||
mount( <ButtonWithForwardedRef ref={ ref } /> ); | ||
|
||
expect( ref.current.nodeName ).toBe( 'button' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test will fail when unskipped: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may take another few weeks until we can unskip those tests :( |
||
} ); | ||
} ); | ||
} ); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// [TEMPORARY]: Button uses React.forwardRef, added in [email protected] but not yet | ||
// supported by Enzyme as of [email protected] . This mock unwraps | ||
// the ref forwarding, so any tests relying on this behavior will fail. | ||
// | ||
// See: https://github.com/airbnb/enzyme/issues/1604 | ||
// See: https://github.com/airbnb/enzyme/pull/1592/files | ||
jest.mock( '../../components/button', () => { | ||
const { Button: RawButton } = require.requireActual( '../../components/button' ); | ||
const { Component } = require( 'react' ); | ||
|
||
return class Button extends Component { | ||
render() { | ||
return RawButton( this.props ); | ||
} | ||
}; | ||
} ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we e.g. create an issue to remind us to unskip this in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created at #7005