Skip to content

Commit

Permalink
Added function and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
CurtisHumphrey committed Feb 14, 2017
1 parent b1db7c7 commit d3c8cb0
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
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
10 changes: 10 additions & 0 deletions index.js
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;
26 changes: 26 additions & 0 deletions package.json
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"
}

0 comments on commit d3c8cb0

Please sign in to comment.