Skip to content

Commit b2f79bc

Browse files
committed
add currentStateIndex test
1 parent d231e4c commit b2f79bc

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

test/instrument.spec.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ describe('instrument', () => {
335335
expect(liftedStoreState.currentStateIndex).toBe(2);
336336
});
337337

338-
it('should handle skipped actions', () => {
338+
it('should remove skipped actions once committed', () => {
339339
configuredStore.dispatch({ type: 'INCREMENT' });
340340
configuredLiftedStore.dispatch(ActionCreators.toggleAction(1));
341341
configuredStore.dispatch({ type: 'INCREMENT' });
@@ -382,6 +382,56 @@ describe('instrument', () => {
382382

383383
spy.restore();
384384
});
385+
386+
it('should update currentStateIndex when auto-committing', () => {
387+
let spy = spyOn(console, 'error');
388+
389+
configuredStore.dispatch({ type: 'INCREMENT' });
390+
configuredStore.dispatch({ type: 'INCREMENT' });
391+
392+
let liftedStoreState = configuredLiftedStore.getState();
393+
expect(liftedStoreState.currentStateIndex).toBe(2);
394+
395+
configuredStore.dispatch({ type: 'INCREMENT' });
396+
397+
liftedStoreState = configuredLiftedStore.getState();
398+
let currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex];
399+
// currentStateIndex stays at 2 when an action is committed
400+
expect(liftedStoreState.currentStateIndex).toBe(2);
401+
expect(currentComputedState.state).toBe(3);
402+
403+
configuredStore.replaceReducer(counterWithBug);
404+
configuredStore.dispatch({ type: 'DECREMENT' });
405+
configuredStore.dispatch({ type: 'DECREMENT' });
406+
configuredStore.dispatch({ type: 'DECREMENT' });
407+
configuredStore.dispatch({ type: 'INCREMENT' });
408+
configuredStore.dispatch({ type: 'INCREMENT' });
409+
liftedStoreState = configuredLiftedStore.getState();
410+
currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex];
411+
// currentStateIndex continues to increment while non-committed action causes error
412+
expect(liftedStoreState.currentStateIndex).toBe(5);
413+
expect(currentComputedState.state).toBe(3);
414+
expect(currentComputedState.error).toExist;
415+
416+
configuredStore.replaceReducer(counterWithAnotherBug);
417+
liftedStoreState = configuredLiftedStore.getState();
418+
currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex];
419+
// currentStateIndex adjusts correctly when multiple actions are committed
420+
expect(liftedStoreState.currentStateIndex).toBe(2);
421+
expect(currentComputedState.state).toBe(0);
422+
expect(currentComputedState.error).toExist;
423+
424+
configuredLiftedStore.dispatch(ActionCreators.jumpToState(0));
425+
configuredStore.replaceReducer(counter);
426+
liftedStoreState = configuredLiftedStore.getState();
427+
// currentStateIndex stays at 0 as actions are committed
428+
currentComputedState = liftedStoreState.computedStates[liftedStoreState.currentStateIndex];
429+
expect(liftedStoreState.currentStateIndex).toBe(0);
430+
expect(currentComputedState.state).toBe(0);
431+
expect(currentComputedState.error).toNotExist;
432+
433+
spy.restore();
434+
});
385435
});
386436

387437
describe('Import State', () => {

0 commit comments

Comments
 (0)