Skip to content

Commit

Permalink
test(index.js): improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed Jul 10, 2017
1 parent f67b17f commit d9cffd4
Showing 1 changed file with 36 additions and 2 deletions.
38 changes: 36 additions & 2 deletions test/index.js
Expand Up @@ -12,7 +12,7 @@ function testCase(input, args, output, done) {
expect(signal).not.to.exist
if (output instanceof Error) {
expect(code).not.to.equal(0)
expect(errchunks.join('')).to.match(new RegExp("Error: " + output.message))
expect(errchunks.join('')).to.match(new RegExp(output.message))
} else {
expect(errchunks.join('')).to.equal('')
expect(outchunks.join('')).to.equal(output)
Expand All @@ -26,14 +26,30 @@ function testCase(input, args, output, done) {
}

describe('lambduh', function () {
it("errors if first argument isn't a function", function (done) {
it("errors if last argument isn't a function", function (done) {
testCase(
'input',
'2881234',
new Error("invalid function"),
done
)
})
it("errors if function argument is missing", function (done) {
testCase(
'input',
[],
new Error('See ' + require('../package.json').repository.url + ' for usage information.'),
done
)
})
it("errors if function argument is empty", function (done) {
testCase(
'input',
['mv', ''],
new Error('missing function'),
done
)
})
describe('pickInputMode', function () {
it('works for basic lambda', function () {
expect(pickInputMode(' lines => lines.reverse()')).to.equal('lines')
Expand Down Expand Up @@ -111,6 +127,24 @@ describe('lambduh', function () {
done
)
})
it('breaks when function returns false', function (done) {
var lines = ['a', 'b', 'c']
testCase(
lines.join('\n') + '\n',
'(line, index) => index < 2 ? line : false',
['a', 'b'].join('\n') + '\n',
done
)
})
it("doesn't output null or undefined return values", function (done) {
var lines = ['a', 'b', 'c']
testCase(
lines.join('\n') + '\n',
'(line, index) => index === 1 ? null : line',
['a', 'c'].join('\n') + '\n',
done
)
})
})
describe('linesMode', function () {
it('works for valid input', function (done) {
Expand Down

0 comments on commit d9cffd4

Please sign in to comment.