@@ -4,30 +4,52 @@ import isPlainObject from 'lodash.isplainobject';
44describe ( 'createAction()' , ( ) => {
55 describe ( 'resulting action creator' , ( ) => {
66 const type = 'TYPE' ;
7- const actionCreator = createAction ( type , b => b ) ;
8- const foobar = { foo : 'bar' } ;
9- const action = actionCreator ( foobar ) ;
107
118 it ( 'returns plain object' , ( ) => {
9+ const actionCreator = createAction ( type , b => b ) ;
10+ const foobar = { foo : 'bar' } ;
11+ const action = actionCreator ( foobar ) ;
1212 expect ( isPlainObject ( action ) ) . to . be . true ;
1313 } ) ;
1414
1515 it ( 'uses return value as payload' , ( ) => {
16+ const actionCreator = createAction ( type , b => b ) ;
17+ const foobar = { foo : 'bar' } ;
18+ const action = actionCreator ( foobar ) ;
1619 expect ( action . payload ) . to . equal ( foobar ) ;
1720 } ) ;
1821
1922 it ( 'has no extraneous keys' , ( ) => {
23+ const actionCreator = createAction ( type , b => b ) ;
24+ const foobar = { foo : 'bar' } ;
25+ const action = actionCreator ( foobar ) ;
2026 expect ( action ) . to . deep . equal ( {
2127 type,
2228 payload : foobar
2329 } ) ;
2430 } ) ;
2531
2632 it ( 'uses identity function if actionCreator is not a function' , ( ) => {
27- expect ( createAction ( type ) ( foobar ) ) . to . deep . equal ( {
33+ const actionCreator = createAction ( type ) ;
34+ const foobar = { foo : 'bar' } ;
35+ const action = actionCreator ( foobar ) ;
36+ expect ( action ) . to . deep . equal ( {
2837 type,
2938 payload : foobar
3039 } ) ;
3140 } ) ;
41+
42+ it ( 'accepts a second parameter for adding meta to object' , ( ) => {
43+ const actionCreator = createAction ( type , null , ( { cid } ) => ( { cid } ) ) ;
44+ const foobar = { foo : 'bar' , cid : 5 } ;
45+ const action = actionCreator ( foobar ) ;
46+ expect ( action ) . to . deep . equal ( {
47+ type,
48+ payload : foobar ,
49+ meta : {
50+ cid : 5
51+ }
52+ } ) ;
53+ } ) ;
3254 } ) ;
3355} ) ;
0 commit comments