-
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.
Blocks: Update ToggleControl to pass boolean onChange (#4720)
* Blocks: Update ToggleControl to pass boolean onChange * Blocks: Simply ToggleControl help describedby assignment
- Loading branch information
Showing
2 changed files
with
80 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
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { mount } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ToggleControl from '../'; | ||
|
||
describe( 'ToggleControl', () => { | ||
it( 'triggers change callback with numeric value', () => { | ||
// Mount: With shallow, cannot find input child of BaseControl | ||
const onChange = jest.fn(); | ||
const wrapper = mount( <ToggleControl onChange={ onChange } /> ); | ||
|
||
wrapper.find( 'input' ).simulate( 'change', { target: { checked: true } } ); | ||
|
||
expect( onChange ).toHaveBeenCalledWith( true ); | ||
} ); | ||
|
||
describe( 'help', () => { | ||
it( 'does not render input with describedby if no help prop', () => { | ||
// Mount: With shallow, cannot find input child of BaseControl | ||
const onChange = jest.fn(); | ||
const wrapper = mount( <ToggleControl onChange={ onChange } /> ); | ||
|
||
const input = wrapper.find( 'input' ); | ||
|
||
expect( input.prop( 'aria-describedby' ) ).toBeUndefined(); | ||
} ); | ||
|
||
it( 'renders input with describedby if help prop', () => { | ||
// Mount: With shallow, cannot find input child of BaseControl | ||
const onChange = jest.fn(); | ||
const wrapper = mount( <ToggleControl help onChange={ onChange } /> ); | ||
|
||
const input = wrapper.find( 'input' ); | ||
|
||
expect( input.prop( 'aria-describedby' ) ).toMatch( /^inspector-toggle-control-.*__help$/ ); | ||
} ); | ||
} ); | ||
} ); |