-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1db7c7
commit d3c8cb0
Showing
3 changed files
with
87 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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('<Example />', () => { | ||
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(<Example {...props} />) | ||
expect(wrapper).to.exist | ||
}) | ||
}) | ||
``` | ||
|
||
### API | ||
|
||
* Takes just one argument: a sinon.sandbox |
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,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; |
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,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" | ||
} |