Skip to content

Commit

Permalink
Merge pull request #202 from nason/awaitWithAsyncFnTest
Browse files Browse the repository at this point in the history
Add test case for descriptor with meta + payload functions
  • Loading branch information
nason authored Jul 14, 2018
2 parents 85aa8fb + 004a7f3 commit 1ed4ab0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
27 changes: 27 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 1ed4ab0

Please sign in to comment.