-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
cache finding suggestions for prop words
- Loading branch information
1 parent
e95ee2c
commit 810ae12
Showing
2 changed files
with
68 additions
and
24 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 @@ | ||
import { customPropTypes } from 'src/lib' | ||
|
||
describe('suggest prop type', () => { | ||
it('should throw error when non-array argument given', () => { | ||
const propType = customPropTypes.suggest('foo') | ||
expect(() => propType({ name: 'bar' }, 'name', 'FooComponent')).to.throw( | ||
Error, | ||
/Invalid argument supplied to suggest, expected an instance of array./, | ||
) | ||
}) | ||
|
||
it('should return undefined when prop is valid', () => { | ||
const propType = customPropTypes.suggest(['foo', 'bar', 'baz']) | ||
expect(propType({ name: 'bar' }, 'name', 'FooComponent')).to.equal(undefined) | ||
}) | ||
|
||
it('should return Error with suggestions when prop is invalid', () => { | ||
const propType = customPropTypes.suggest(['foo', 'bar', 'baz']) | ||
const props = { name: 'bad', title: 'bat words' } | ||
|
||
const resultFooComponent = propType(props, 'name', 'FooComponent') | ||
expect(resultFooComponent).to.be.an.instanceof(Error) | ||
expect(resultFooComponent.message).to | ||
.equal(`Invalid prop \`name\` of value \`bad\` supplied to \`FooComponent\`. | ||
Instead of \`bad\`, did you mean: | ||
- bar | ||
- baz | ||
- foo | ||
`) | ||
|
||
const resultBarComponent = propType(props, 'title', 'BarComponent') | ||
expect(resultBarComponent).to.be.an.instanceof(Error) | ||
expect(resultBarComponent.message).to | ||
.equal(`Invalid prop \`title\` of value \`bat words\` supplied to \`BarComponent\`. | ||
Instead of \`bat words\`, did you mean: | ||
- bar | ||
- baz | ||
- foo | ||
`) | ||
}) | ||
}) |