@@ -4,33 +4,51 @@ import isPlainObject from 'lodash.isplainobject';
44describe ( 'createAction()' , ( ) => {
55 describe ( 'resulting action creator' , ( ) => {
66 const type = 'TYPE' ;
7- const actionCreator = createAction ( type , b => b , ( { cid } ) => ( { cid} ) ) ;
8- const foobar = { foo : 'bar' , cid : 5 } ;
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,
22- payload : foobar ,
23- meta : {
24- cid : 5
25- }
28+ payload : foobar
2629 } ) ;
2730 } ) ;
2831
29- it ( 'uses identity function if actionCreator and/or metaCreator is not a function' , ( ) => {
30- expect ( createAction ( type ) ( foobar ) ) . to . deep . equal ( {
32+ it ( 'uses identity function if actionCreator is not a function' , ( ) => {
33+ const actionCreator = createAction ( type ) ;
34+ const foobar = { foo : 'bar' } ;
35+ const action = actionCreator ( foobar ) ;
36+ expect ( action ) . to . deep . equal ( {
37+ type,
38+ payload : foobar
39+ } ) ;
40+ } ) ;
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 ( {
3147 type,
3248 payload : foobar ,
33- meta : foobar
49+ meta : {
50+ cid : 5
51+ }
3452 } ) ;
3553 } ) ;
3654 } ) ;
0 commit comments