-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2344 from WordPress/add/editable-proptypes
Editable: Add prop types to warn on non-array value
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
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 { shallow } from 'enzyme'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Editable from '../'; | ||
|
||
describe( 'Editable', () => { | ||
describe( '.propTypes', () => { | ||
/* eslint-disable no-console */ | ||
let consoleError; | ||
beforeEach( () => { | ||
consoleError = console.error; | ||
console.error = jest.fn(); | ||
} ); | ||
|
||
afterEach( () => { | ||
console.error = consoleError; | ||
} ); | ||
|
||
it( 'should warn when rendered with string value', () => { | ||
shallow( <Editable value="Uh oh!" /> ); | ||
|
||
expect( console.error ).toHaveBeenCalled(); | ||
} ); | ||
|
||
it( 'should not warn when rendered with undefined value', () => { | ||
shallow( <Editable /> ); | ||
|
||
expect( console.error ).not.toHaveBeenCalled(); | ||
} ); | ||
|
||
it( 'should not warn when rendered with array value', () => { | ||
shallow( <Editable value={ [ 'Oh, good' ] } /> ); | ||
|
||
expect( console.error ).not.toHaveBeenCalled(); | ||
} ); | ||
/* eslint-enable no-console */ | ||
} ); | ||
} ); |