From 69c3c56437d3d38170fad213923e47bbf009e2a5 Mon Sep 17 00:00:00 2001 From: Mike Nason Date: Sat, 14 Jul 2018 17:23:33 -0400 Subject: [PATCH 1/2] test: actionWith with payload and meta functions --- test/index.js | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/index.js b/test/index.js index e613a84..a822851 100644 --- a/test/index.js +++ b/test/index.js @@ -868,6 +868,33 @@ test('actionWith', async t => { 'must set FSA error property to true if a custom meta function throws' ); + const descriptor5 = { + type: 'REQUEST', + payload: () => 'somePayload', + meta: () => new Promise(resolve => setTimeout(() => resolve('someMeta'), 250)), + error: true + }; + const fsa5 = await actionWith(descriptor5); + t.equal( + fsa5.type, + 'REQUEST', + 'must set FSA type property to incoming descriptor type property' + ); + t.equal( + fsa5.payload, + 'somePayload', + 'must set FSA payload property to incoming descriptor payload property' + ); + t.equal( + fsa5.meta, + 'someMeta', + 'must set FSA meta property to incoming descriptor meta property' + ); + t.ok( + fsa5.error, + 'must set FSA error property to incoming descriptor error property' + ); + t.end(); }); From 004a7f3507fed3eebb4237b0c3666d3ab51a7871 Mon Sep 17 00:00:00 2001 From: Mike Nason Date: Sat, 14 Jul 2018 17:24:19 -0400 Subject: [PATCH 2/2] fix: default args to empty array if none are passed --- src/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util.js b/src/util.js index b6c4adc..8499311 100644 --- a/src/util.js +++ b/src/util.js @@ -68,7 +68,7 @@ function normalizeTypeDescriptors(types) { * @param {array} args - The array of arguments for `payload` and `meta` function properties * @returns {object} */ -async function actionWith(descriptor, args) { +async function actionWith(descriptor, args = []) { try { descriptor.payload = typeof descriptor.payload === 'function'