From 26a482f99a28dd1d10523a6f56562c3487499bcc Mon Sep 17 00:00:00 2001 From: jero Date: Fri, 27 Sep 2019 15:45:21 +0300 Subject: [PATCH] test(makeactioncreator): update test against "payload" also test for "meta" improves #35 --- .../makeActionCreator.test.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/app/store/helpers/makeActionCreator/makeActionCreator.test.js b/src/app/store/helpers/makeActionCreator/makeActionCreator.test.js index 94f9078a..5c6cc26e 100644 --- a/src/app/store/helpers/makeActionCreator/makeActionCreator.test.js +++ b/src/app/store/helpers/makeActionCreator/makeActionCreator.test.js @@ -3,25 +3,33 @@ import makeActionCreator from './makeActionCreator'; describe('makeActionCreator', () => { const GET_INFO = 'GET_INFO'; - const name = { name: 'Jero' }; + const payload = { user: { name: 'Jero' } }; it('should return an action creator', () => { - const actionCreator = makeActionCreator(GET_INFO, 'user'); + const actionCreator = makeActionCreator(GET_INFO); expect(typeof actionCreator).toBe('function'); }); it('should return an action when calling the action creator', () => { - const actionCreator = makeActionCreator(GET_INFO, 'user'); - const action = actionCreator(name); + const actionCreator = makeActionCreator(GET_INFO); + const action = actionCreator(payload); expect(action).toEqual(expect.objectContaining({ type: GET_INFO })); }); it('should contain action\'s data under "payload" property', () => { - const actionCreator = makeActionCreator(GET_INFO, 'user'); - const action = actionCreator(name); - const payload = { user: name }; + const actionCreator = makeActionCreator(GET_INFO); + const action = actionCreator(payload); const expectedData = { type: GET_INFO, payload }; expect(action).toHaveProperty('payload'); expect(action).toEqual(expectedData); }); + + it('can contain optional "meta" property and its metadata', () => { + const actionCreator = makeActionCreator(GET_INFO); + const meta = { callMe: 'some metada for any purpose' }; + const action = actionCreator(payload, meta); + const expectedData = { type: GET_INFO, payload, meta }; + expect(action).toHaveProperty('meta'); + expect(action).toEqual(expectedData); + }); });