diff --git a/README.md b/README.md index 3ab47a4..0716aef 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,53 @@ # react-proptype-error-catcher Causes React PropType errors to fail the test + +### Installation + +Using [npm](https://www.npmjs.com/): + + $ npm install --save-dev react-proptype-error-catcher + +### Requirements + +* [React](https://github.com/facebook/react) +* Testing with [sinon](https://github.com/sinonjs/sinon) +* Testing with [enzyme](http://airbnb.io/enzyme/) + +### Usage + +``` js +import React from 'react' +import { + shallow, +} from 'enzyme' + +import Example from './Example' +import proptype_error_catcher from 'react-proptype-error-catcher' + +describe('', () => { + let sandbox + let props + + beforeEach(() => { + sandbox = sinon.sandbox.create() + + proptype_error_catcher(sandbox) + + props = { + show: true, + } + }) + + afterEach(() => { + sandbox.restore() + }) + it('with normal props it should render without errors', () => { + const wrapper = shallow() + expect(wrapper).to.exist + }) +}) +``` + +### API + +* Takes just one argument: a sinon.sandbox diff --git a/index.js b/index.js new file mode 100644 index 0000000..58040a6 --- /dev/null +++ b/index.js @@ -0,0 +1,10 @@ +'use strict'; + +function proptype_error_catcher (sandbox) { + sandbox.stub(console, 'error', function (message) { + if (!message.includes('Failed prop type')) return; + throw new Error(message); + }); +} + +module.exports = proptype_error_catcher; diff --git a/package.json b/package.json new file mode 100644 index 0000000..2f29f77 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "name": "react-proptype-error-catcher", + "version": "1.0.0", + "description": "Causes React PropType errors to fail the test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/CurtisHumphrey/react-proptype-error-catcher.git" + }, + "keywords": [ + "react", + "sinon", + "enzyme", + "testing", + "proptypes" + ], + "author": "Curtis M. Humphrey, Ph.D.", + "license": "MIT", + "bugs": { + "url": "https://github.com/CurtisHumphrey/react-proptype-error-catcher/issues" + }, + "homepage": "https://github.com/CurtisHumphrey/react-proptype-error-catcher#readme" +}