diff --git a/test/provider.js b/test/provider.js index 9e47caa..94f3353 100644 --- a/test/provider.js +++ b/test/provider.js @@ -92,101 +92,101 @@ describe('preact-redux', () => { }); }); - describe('connectAdvanced()', () => { - it('should connectAdvanced component to store', () => { - let initialState = { - a: 'a', - b: 'b' - }; - - let reducer = (state=initialState, action) => { - switch (action.type) { - case 'A': return { ...state, a: action.data }; - case 'B': return { ...state, b: action.data }; - default: return state; - } - }; - - let store = createStore(reducer); - let Child = sinon.stub().returns(
); - - let spies = {}; - - function shallowDiffers (a, b) { - for (let i in a) if (!(i in b)) return true; - for (let i in b) if (a[i] !== b[i]) return true; - return false; - } - - let ConnectedChild = connectAdvanced((dispatch) => { - /** - * from https://github.com/reactjs/react-redux/blob/master/docs/api.md - * If a consecutive call to selector returns the same object (===) as its previous call, - * the component will not be re-rendered. - * It's the responsibility of selector to return that previous object when appropriate. - */ - let result = {}; - const onA = spies.onA = sinon.spy(data => dispatch({type: 'A', data})); - const onB = spies.onB = sinon.spy(data => dispatch({type: 'B', data})); - - return ({a, b}, {c}) => { - const nextResult = { - a, - b, - c, - onA, - onB - }; - - if (shallowDiffers(result, nextResult)) { - result = nextResult; - } - return result; - }; - })(Child); - - render(( + describe('connectAdvanced()', () => { + it('should connectAdvanced component to store', () => { + let initialState = { + a: 'a', + b: 'b' + }; + + let reducer = (state=initialState, action) => { + switch (action.type) { + case 'A': return { ...state, a: action.data }; + case 'B': return { ...state, b: action.data }; + default: return state; + } + }; + + let store = createStore(reducer); + let Child = sinon.stub().returns(); + + let spies = {}; + + function shallowDiffers (a, b) { + for (let i in a) if (!(i in b)) return true; + for (let i in b) if (a[i] !== b[i]) return true; + return false; + } + + let ConnectedChild = connectAdvanced((dispatch) => { + /** + * from https://github.com/reactjs/react-redux/blob/master/docs/api.md + * If a consecutive call to selector returns the same object (===) as its previous call, + * the component will not be re-rendered. + * It's the responsibility of selector to return that previous object when appropriate. + */ + let result = {}; + const onA = spies.onA = sinon.spy(data => dispatch({type: 'A', data})); + const onB = spies.onB = sinon.spy(data => dispatch({type: 'B', data})); + + return ({a, b}, {c}) => { + const nextResult = { + a, + b, + c, + onA, + onB + }; + + if (shallowDiffers(result, nextResult)) { + result = nextResult; + } + return result; + }; + })(Child); + + render((