Skip to content

Commit

Permalink
Prevent check if method of agent is async (#11)
Browse files Browse the repository at this point in the history
Co-authored-by: Albert Pérez <albert.perez@immfly.com>
  • Loading branch information
sonofjavascript and Albert Pérez committed Jun 26, 2020
1 parent 1243f78 commit 6665d5b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/utils/reducer/asyncBus/validator/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@ import { METHODS } from '../../static'
const errorPattern = (method, type) => `The method '${method}' ${type} in the client agent`

export const checkFn = (fn, method) => {
if (!fn) {
throw new Error(errorPattern(method, 'does not exist'))
}
if (fn) return

if (fn() instanceof Promise) return

throw new Error(errorPattern(method, 'is not an async function'))
throw new Error(errorPattern(method, 'does not exist'))
}

export const checkMethod = (method) => {
Expand Down
6 changes: 0 additions & 6 deletions src/utils/reducer/asyncBus/validator/utils/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ test('checkFn - Throw error when fn is not defined', () => {
}).toThrowError(new Error('The method \'undefined\' does not exist in the client agent'))
})

test('checkFn - Throw error when fn is not an async method', () => {
expect(() => {
checkFn(() => {}, '::method::')
}).toThrowError(new Error('The method \'::method::\' is not an async function in the client agent'))
})

test('checkFn - Return undefined when fn is valid', () => {
const result = checkFn(() => Promise.resolve(), '::method::')
expect(result).not.toBeDefined()
Expand Down

0 comments on commit 6665d5b

Please sign in to comment.