Skip to content

Commit

Permalink
test: alt opts to bind()
Browse files Browse the repository at this point in the history
  • Loading branch information
mvayngrib committed Feb 22, 2019
1 parent 789e81e commit 02c31de
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions test/normalizeBindOptions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ const normalizeBindOptions = require('../normalizeBindOptions')
const prettify = obj => JSON.stringify(obj, null, 2)

describe('normalizeBindOptions', () => {
const args = [
{ name: 'port', value: 1234 },
{ name: 'address', value: '1.2.3.4' },
{ name: 'callback', value: () => {} },
]

it('should support all combinations of arguments', () => {
it('should support all combinations of arguments for [port], [address], [callback]', () => {
const args = [
{ name: 'port', value: 1234 },
{ name: 'address', value: '1.2.3.4' },
{ name: 'callback', value: () => {} },
]

// check every combination of arguments (retaining order)
// use a bit mask to decide whether to keep an argument
for (let i = 0, numCombinations = Math.pow(2, args.length); i < numCombinations; i++) {
Expand All @@ -26,4 +27,29 @@ describe('normalizeBindOptions', () => {
}
}
})

it('should support all combinations of arguments for [options], [callback]', () => {
const callback = () => {}
const inOut = [
[
[{ port: 123 }, callback], { port: 123, callback }
],
[
[{ port: 123 }], { port: 123 }
],
[
[callback], { callback }
],
]

for (const [args, expected] of inOut) {
let result
try {
result = normalizeBindOptions(...args)
assert.deepEqual(result, expected)
} catch (err) {
throw new Error(`for args: ${prettify(args)}\nexpected: ${prettify(expected)}\ngot ${prettify(result)}`)
}
}
})
})

0 comments on commit 02c31de

Please sign in to comment.