From 092bb66d03b5200cc2818011b0c09acb33620cf9 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 27 Sep 2015 20:13:38 +0300 Subject: [PATCH] Add performance regression tests --- test/devTools.spec.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/devTools.spec.js b/test/devTools.spec.js index 672fb8b9..af47f858 100644 --- a/test/devTools.spec.js +++ b/test/devTools.spec.js @@ -212,4 +212,35 @@ describe('devTools', () => { storeWithBug.dispatch({ type: 'SET_UNDEFINED' }); expect(storeWithBug.getState()).toBe(2); }); + + it('should not recompute states on every action', () => { + let reducerCalls = 0; + let monitoredStore = devTools()(createStore)(() => reducerCalls++); + expect(reducerCalls).toBe(1); + monitoredStore.dispatch({ type: 'INCREMENT' }); + monitoredStore.dispatch({ type: 'INCREMENT' }); + monitoredStore.dispatch({ type: 'INCREMENT' }); + expect(reducerCalls).toBe(4); + }); + + it('should not recompute states when jumping to state', () => { + let reducerCalls = 0; + let monitoredStore = devTools()(createStore)(() => reducerCalls++); + let monitoredDevToolsStore = monitoredStore.devToolsStore; + + expect(reducerCalls).toBe(1); + monitoredStore.dispatch({ type: 'INCREMENT' }); + monitoredStore.dispatch({ type: 'INCREMENT' }); + monitoredStore.dispatch({ type: 'INCREMENT' }); + expect(reducerCalls).toBe(4); + + monitoredDevToolsStore.dispatch(ActionCreators.jumpToState(0)); + expect(reducerCalls).toBe(4); + + monitoredDevToolsStore.dispatch(ActionCreators.jumpToState(1)); + expect(reducerCalls).toBe(4); + + monitoredDevToolsStore.dispatch(ActionCreators.jumpToState(3)); + expect(reducerCalls).toBe(4); + }); });