Skip to content

Commit

Permalink
Better validation in test-each
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed May 18, 2019
1 parent a379b31 commit a6aa98c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/helpers/test_each/input.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
// Parse and validate main input
export const parseInput = function(inputArgs) {
const iterables = inputArgs.slice(0, -1)
iterables.forEach(validateIterable)

const func = inputArgs[inputArgs.length - 1]
validateFunc(func)

return { iterables, func }
}

const validateIterable = function(iterable) {
if (iterable[Symbol.iterator] === undefined && !isRepeat(iterable)) {
throw new TypeError(`Argument must be an iterable or a positive integer: ${iterable}`)
}
}

export const isRepeat = function(iterable) {
return Number.isInteger(iterable) && iterable >= 0
}

const validateFunc = function(func) {
if (typeof func !== 'function') {
throw new TypeError(`Last argument must be a function: ${func}`)
Expand Down

0 comments on commit a6aa98c

Please sign in to comment.