Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottcorgan committed Oct 18, 2015
1 parent c55975e commit 9d5ebe6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "flag",
"main": "index.js",
"scripts": {
"test": "echo '1'"
"test": "node ./test.js | tap-spec"
},
"repository": {
"type": "git",
Expand All @@ -26,5 +26,11 @@
"dependencies": {
"as-array": "^2.0.0",
"ramda": "^0.18.0"
},
"devDependencies": {
"@cli/alias": "^0.3.0",
"@cli/handler": "^0.3.0",
"tap-spec": "^4.1.0",
"tessed": "^2.2.0"
}
}
65 changes: 65 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
var namespace = require('tessed').namespace
var flag = require('./')
var alias = require('@cli/alias')
var handler = require('@cli/handler')

var test = namespace('flag')

test('flag()', function (t) {

var fn1 = function () {}
var f = flag(
alias('-t'),
handler(fn1)
)

t.equal(typeof f, 'function', 'returns a function')
t.equal(f().type, 'flag', 'type')
t.deepEqual(f().value, {
alias: ['t'],
handler: [fn1]
}, 'value')
t.equal(f().options, undefined, 'no options')
t.deepEqual(f({key: 'value'}).options, {key: 'value'}, 'with options')
})

test('combines multiple values', function (t) {

var fn1 = function () {}
var fn2 = function () {}
var f = flag(
alias('--one'),
alias('-t'),
handler(fn1),
handler(fn2)
)

t.deepEqual(f().value, {
alias: ['one', 't'],
handler: [fn1, fn2]
}, 'value')
})

test('custom arguments', function (t) {

var f1 = flag(alias('-t'))
var f2 = flag(alias('--test', '-t'))

t.deepEqual(
f1().args([], {t: 't small', test: 't full'}),
['t small'],
'args function first flag'
)

t.deepEqual(
f2().args([], {t: 't small', test: 't full'}),
['t full', 't small'],
'args function second flag'
)

t.deepEqual(
f2().args([], {t: 't small'}),
['t small'],
'removes undefined values'
)
})

0 comments on commit 9d5ebe6

Please sign in to comment.