Skip to content

Commit

Permalink
handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevnz committed Jul 12, 2020
1 parent 40bd27c commit a3a19d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,8 @@
"filename": true,
"format": "svg"
}
]
],
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
"ancestorSeparator": "",
"usePathForSuiteName": "true"
}
}
}
11 changes: 11 additions & 0 deletions src/__tests__/composer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('Composer to compose functions', () => {
await delay(5)
return func3(val)
}
const errorFunc = () => {
throw new Error('The Error')
}
it('should take 3 functions as parameters and execute them on a value', async () => {
const chain = await composer(asyncFunc1, asyncFunc2, asyncFunc3)
const result = await chain('dude')
Expand All @@ -38,7 +41,15 @@ describe('Composer to compose functions', () => {
const result = await chain('dude')
expect(result).toBe('DUDE-DUDE!!!-DUDE-DUDE!!!')
})
it('should throw when function errors', async () => {
try {
const chain = composer(func1, func2, errorFunc, func2)

await chain('dude')
} catch (err) {
expect(err.name).toBe('Error')
}
})
const heldFunction1 = async (val, other) => {
await delay(5)
return func3(`${val}-${other}`)
Expand Down
8 changes: 6 additions & 2 deletions src/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@ module.exports = (startValue, ...funcs) =>
resolve(total)
return
}
const result = await el.value(total)
next(result)
try {
const result = await el.value(total)
next(result)
} catch (error) {
return reject(error)
}
}

next(startValue)
Expand Down

0 comments on commit a3a19d6

Please sign in to comment.