From d29b5f10ef5137ab56ecc9615e5e894082db9803 Mon Sep 17 00:00:00 2001 From: kumavis Date: Mon, 2 Oct 2017 13:14:42 -0700 Subject: tx state history - fix bug where initial snapshot was mutated on updateTx --- test/unit/tx-state-history-helper.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test') diff --git a/test/unit/tx-state-history-helper.js b/test/unit/tx-state-history-helper.js index 5bb6c9bee..e5075af88 100644 --- a/test/unit/tx-state-history-helper.js +++ b/test/unit/tx-state-history-helper.js @@ -20,4 +20,26 @@ describe('tx-state-history-helper', function () { }) }) }) + + it('replaying history does not mutate the original obj', function () { + const initialState = { test: true, message: 'hello', value: 1 } + const diff1 = { + "op": "replace", + "path": "/message", + "value": "haay", + } + const diff2 = { + "op": "replace", + "path": "/value", + "value": 2, + } + const history = [initialState, diff1, diff2] + + const beforeStateSnapshot = JSON.stringify(initialState) + const latestState = txStateHistoryHelper.replayHistory(history) + const afterStateSnapshot = JSON.stringify(initialState) + + assert.notEqual(initialState, latestState, 'initial state is not the same obj as the latest state') + assert.equal(beforeStateSnapshot, afterStateSnapshot, 'initial state is not modified during run') + }) }) -- cgit v1.2.3