Skip to content

Commit 5c74b7f

Browse files
committed
fix skipped and spec
1 parent 9bafa7a commit 5c74b7f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/instrument.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer, options
238238
if (options.maxAge && stagedActionIds.length === options.maxAge) {
239239
// If maxAge has been reached, remove oldest action.
240240
delete actionsById[stagedActionIds[1]];
241-
skippedActionIds = skippedActionIds.filter(id => id !== stagedActionIds[0]);
241+
skippedActionIds = skippedActionIds.filter(id => id !== stagedActionIds[1]);
242242
stagedActionIds = [0].concat(stagedActionIds.slice(2));
243243
committedState = computedStates[1].state;
244244
computedStates = computedStates.slice(1);

test/instrument.spec.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -300,27 +300,30 @@ describe('instrument', () => {
300300
let configuredLiftedStore;
301301

302302
beforeEach(() => {
303-
configuredStore = createStore(counter, instrument(undefined, { maxAge: 2 }));
303+
configuredStore = createStore(counter, instrument(undefined, { maxAge: 3 }));
304304
configuredLiftedStore = configuredStore.liftedStore;
305305
});
306306

307-
it('should remove earliest action when maxAge is reached', () => {
307+
it('should auto-commit earliest non-@@INIT action when maxAge is reached', () => {
308+
configuredStore.dispatch({ type: 'INCREMENT' });
308309
configuredStore.dispatch({ type: 'INCREMENT' });
309310
let liftedStoreState = configuredLiftedStore.getState();
310311

311-
expect(configuredStore.getState()).toBe(1);
312-
expect(Object.keys(liftedStoreState.actionsById).length).toBe(2);
312+
expect(configuredStore.getState()).toBe(2);
313+
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
313314
expect(liftedStoreState.committedState).toBe(undefined);
315+
expect(liftedStoreState.stagedActionIds).toInclude(1);
314316

317+
// Triggers auto-commit.
315318
configuredStore.dispatch({ type: 'INCREMENT' });
316319
liftedStoreState = configuredLiftedStore.getState();
317320

318-
expect(configuredStore.getState()).toBe(2);
319-
expect(Object.keys(liftedStoreState.actionsById).length).toBe(2);
320-
expect(liftedStoreState.stagedActionIds).toExclude(0);
321+
expect(configuredStore.getState()).toBe(3);
322+
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
323+
expect(liftedStoreState.stagedActionIds).toExclude(1);
321324
expect(liftedStoreState.computedStates[0].state).toBe(1);
322325
expect(liftedStoreState.committedState).toBe(1);
323-
expect(liftedStoreState.currentStateIndex).toBe(1);
326+
expect(liftedStoreState.currentStateIndex).toBe(2);
324327
});
325328

326329
it('should handle skipped actions', () => {

0 commit comments

Comments
 (0)