diff --git a/examples/counter/src/containers/Root.dev.js b/examples/counter/src/containers/Root.dev.js index dc9e594a..00acca46 100644 --- a/examples/counter/src/containers/Root.dev.js +++ b/examples/counter/src/containers/Root.dev.js @@ -13,7 +13,7 @@ export default class Root extends Component { - + ); diff --git a/src/connectMonitor.js b/src/connectMonitor.js index 9ff7e892..e9fb3960 100644 --- a/src/connectMonitor.js +++ b/src/connectMonitor.js @@ -1,6 +1,40 @@ +import React, { Component } from 'react'; import { connect } from 'react-redux'; import { ActionCreators } from './devTools'; export default function connectMonitor(Monitor) { - return connect(state => state, ActionCreators)(Monitor); + const ConnectedMonitor = connect(state => state, ActionCreators)(Monitor); + + class DevTools extends Component { + static propTypes = { + store(props, propName, componentName) { + if (!props.store) { + return new Error('Required prop `store` was not specified in `' + componentName + '`.'); + } + if (!props.store.devToolsStore) { + return new Error( + 'Could not find the DevTools store inside the `store` prop passed to `' + + componentName + + '`. Have you applied the devTools() store enhancer?' + ); + } + } + }; + + render() { + const { store } = this.props; + if (!store) { + return null; + } + + const { devToolsStore } = store; + if (!devToolsStore) { + return null; + } + + return ; + } + } + + return DevTools; } diff --git a/test/createDevTools.spec.js b/test/connectMonitor.spec.js similarity index 72% rename from test/createDevTools.spec.js rename to test/connectMonitor.spec.js index 1c4f82d1..bce19426 100644 --- a/test/createDevTools.spec.js +++ b/test/connectMonitor.spec.js @@ -2,8 +2,7 @@ import expect from 'expect'; import jsdom from 'mocha-jsdom'; import React, { Component } from 'react'; import TestUtils from 'react-addons-test-utils'; -import createDevTools from '../src/createDevTools'; -import devTools from '../src/devTools'; +import { connectMonitor, devTools } from '../src'; import { createStore } from 'redux'; class MockMonitor extends Component { @@ -12,14 +11,14 @@ class MockMonitor extends Component { } } -describe('createDevTools', () => { +describe('connectMonitor', () => { jsdom(); it('should pass devToolsStore to monitor', () => { const store = devTools()(createStore)(() => {}); - const DevTools = createDevTools(React); + const ConnectedMonitor = connectMonitor(MockMonitor); const tree = TestUtils.renderIntoDocument( - + ); const mockMonitor = TestUtils.findRenderedComponentWithType(tree, MockMonitor); expect(mockMonitor.props.store).toBe(store.devToolsStore); @@ -27,9 +26,9 @@ describe('createDevTools', () => { it('should pass props to monitor', () => { const store = devTools()(createStore)(() => {}); - const DevTools = createDevTools(React); + const ConnectedMonitor = connectMonitor(MockMonitor); const tree = TestUtils.renderIntoDocument( - + ); const mockMonitor = TestUtils.findRenderedComponentWithType(tree, MockMonitor); expect(mockMonitor.props.one).toBe(1); @@ -37,7 +36,7 @@ describe('createDevTools', () => { }); it('should subscribe monitor to store updates', () => { - const DevTools = createDevTools(React); + const ConnectedMonitor = connectMonitor(MockMonitor); const store = devTools()(createStore)( (state, action) => { switch (action.type) { @@ -50,7 +49,7 @@ describe('createDevTools', () => { 0 ); const tree = TestUtils.renderIntoDocument( - + ); store.dispatch({type: 'INC'}); @@ -63,21 +62,19 @@ describe('createDevTools', () => { }); it('should warn if devTools() not in middleware', () => { - const spy = expect.spyOn(console, 'error'); const store = createStore(() => {}); - const DevTools = createDevTools(React); + const ConnectedMonitor = connectMonitor(MockMonitor); - expect( - TestUtils.renderIntoDocument, - ).withArgs( - - ).toThrow(); + // Force to re-evaluate propType checks on every run + ConnectedMonitor.displayName = Math.random().toString(); + + const spy = expect.spyOn(console, 'error'); + TestUtils.renderIntoDocument(); + spy.restore(); expect(spy.calls).toContain( - /Could not find the devTools store/, + /Could not find the DevTools store/, (call, errMsg) => call.arguments[0].match(errMsg) ); - - spy.restore(); }); }); diff --git a/test/index.spec.js b/test/index.spec.js deleted file mode 100644 index e69de29b..00000000