Skip to content

Commit

Permalink
test(makeactioncreator): update test against "payload"
Browse files Browse the repository at this point in the history
also test for "meta"

improves #35
  • Loading branch information
aneurysmjs committed Sep 27, 2019
1 parent 73e2332 commit 26a482f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions src/app/store/helpers/makeActionCreator/makeActionCreator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

0 comments on commit 26a482f

Please sign in to comment.