From 28d2b77f1967df77750093715116705e8f1f9275 Mon Sep 17 00:00:00 2001 From: MrOrz Date: Tue, 3 Oct 2017 02:27:51 +0800 Subject: [PATCH] Add simple unit tests for reducer.js --- util/__tests__/__snapshots__/reducer.js.snap | 14 +++++++++++++ util/__tests__/reducer.js | 22 +++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 util/__tests__/__snapshots__/reducer.js.snap diff --git a/util/__tests__/__snapshots__/reducer.js.snap b/util/__tests__/__snapshots__/reducer.js.snap new file mode 100644 index 00000000..f87ba7af --- /dev/null +++ b/util/__tests__/__snapshots__/reducer.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`reducer commonSetState sets state from payload 1`] = ` +Immutable.Map { + "foo": "bar2", +} +`; + +exports[`reducer commonSetState sets state from payload 2`] = ` +Immutable.Map { + "foo": "bar", + "not-exist-key": "new-value", +} +`; diff --git a/util/__tests__/reducer.js b/util/__tests__/reducer.js index 5c972d26..4d667de9 100644 --- a/util/__tests__/reducer.js +++ b/util/__tests__/reducer.js @@ -1,5 +1,25 @@ +import { fromJS } from 'immutable'; +import { commonSetState } from '../reducer'; + describe('reducer', () => { describe('commonSetState', () => { - it('sets state from payload'); + const initState = fromJS({ + state: { + foo: 'bar', + }, + }); + it('sets state from payload', () => { + expect( + commonSetState(initState, { + payload: { key: 'foo', value: 'bar2' }, + }).get('state') + ).toMatchSnapshot(); + + expect( + commonSetState(initState, { + payload: { key: 'not-exist-key', value: 'new-value' }, + }).get('state') + ).toMatchSnapshot(); + }); }); });