1.0.3 • Published 6 years ago

validate-prop-types v1.0.3

Weekly downloads
36
License
MIT
Repository
github
Last release
6 years ago

Validate Prop Types

This package is a modified version of PropTypes.checkPropTypes(), the difference being that it returns errors as an object instead of issuing a console.error.

ExampleComponent.js

const PropTypes = require('prop-types')
const ExampleComponent = () => 'hello'

ExampleComponent.propTypes = {
  a: PropTypes.string.isRequired,
  b: PropTypes.number,
  c: PropTypes.object
}

ExampleComponent.test.js

const assert = require('assert')
const validatePropTypes = require('validate-prop-types')
const ExampleComponent = require('./ExampleComponent')

const data = {
  b: 'a string',
  c: 'another string'
}

assert.deepEqual(validatePropTypes(ExampleComponent.propTypes, data), {
  a: 'The prop `a` is marked as required in `Component`, but its value is `undefined`.',
  b: 'Invalid prop `b` of type `string` supplied to `Component`, expected `number`.',
  c: 'Invalid prop `c` of type `string` supplied to `Component`, expected `object`.'
})
1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago