fix skipped and spec

This commit is contained in:
echenley 2016-02-05 10:26:23 -06:00
parent 9bafa7a0d7
commit 5c74b7f986
2 changed files with 12 additions and 9 deletions

View File

@ -238,7 +238,7 @@ function liftReducerWith(reducer, initialCommittedState, monitorReducer, options
if (options.maxAge && stagedActionIds.length === options.maxAge) {
// If maxAge has been reached, remove oldest action.
delete actionsById[stagedActionIds[1]];
skippedActionIds = skippedActionIds.filter(id => id !== stagedActionIds[0]);
skippedActionIds = skippedActionIds.filter(id => id !== stagedActionIds[1]);
stagedActionIds = [0].concat(stagedActionIds.slice(2));
committedState = computedStates[1].state;
computedStates = computedStates.slice(1);

View File

@ -300,27 +300,30 @@ describe('instrument', () => {
let configuredLiftedStore;
beforeEach(() => {
configuredStore = createStore(counter, instrument(undefined, { maxAge: 2 }));
configuredStore = createStore(counter, instrument(undefined, { maxAge: 3 }));
configuredLiftedStore = configuredStore.liftedStore;
});
it('should remove earliest action when maxAge is reached', () => {
it('should auto-commit earliest non-@@INIT action when maxAge is reached', () => {
configuredStore.dispatch({ type: 'INCREMENT' });
configuredStore.dispatch({ type: 'INCREMENT' });
let liftedStoreState = configuredLiftedStore.getState();
expect(configuredStore.getState()).toBe(1);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(2);
expect(configuredStore.getState()).toBe(2);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
expect(liftedStoreState.committedState).toBe(undefined);
expect(liftedStoreState.stagedActionIds).toInclude(1);
// Triggers auto-commit.
configuredStore.dispatch({ type: 'INCREMENT' });
liftedStoreState = configuredLiftedStore.getState();
expect(configuredStore.getState()).toBe(2);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(2);
expect(liftedStoreState.stagedActionIds).toExclude(0);
expect(configuredStore.getState()).toBe(3);
expect(Object.keys(liftedStoreState.actionsById).length).toBe(3);
expect(liftedStoreState.stagedActionIds).toExclude(1);
expect(liftedStoreState.computedStates[0].state).toBe(1);
expect(liftedStoreState.committedState).toBe(1);
expect(liftedStoreState.currentStateIndex).toBe(1);
expect(liftedStoreState.currentStateIndex).toBe(2);
});
it('should handle skipped actions', () => {