Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] add
sloppy
import, for removing the "exact"ness on a propType…
…s object
- Loading branch information
Showing
3 changed files
with
30 additions
and
2 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,8 @@ | ||
import ownKeys from 'reflect.ownkeys'; | ||
import exact from './'; | ||
|
||
const [semaphore] = ownKeys(exact({})); | ||
|
||
export default function sloppy({ [semaphore]: _, ...propTypes }) { | ||
return propTypes; | ||
} |
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,20 @@ | ||
import test from 'tape'; | ||
import React from 'react'; | ||
import sloppy from '../build/sloppy'; | ||
import exact from '../'; | ||
|
||
test('sloppy', (t) => { | ||
t.equal(typeof sloppy, 'function', 'export is a function'); | ||
|
||
class Component extends React.Component { | ||
render() { return null; } | ||
} | ||
Component.propTypes = exact({}); | ||
|
||
t['throws'](() => <Component a />, EvalError, 'works with exact'); | ||
|
||
Component.propTypes = sloppy(Component.propTypes); | ||
t.doesNotThrow(() => <Component a />, 'sloppy un-exacts it'); | ||
|
||
t.end(); | ||
}); |