Skip to content

Commit

Permalink
Add tests for error conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 13, 2016
1 parent 8b02ef4 commit d74134a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/index.js
Expand Up @@ -11,6 +11,16 @@ describe('convert', function () {
assert.equal(Units.convert('1', 'finney', 'eth'), '0.001')
assert.equal(Units.convert('20', 'gwei', 'eth'), '0.00000002')
})
it('should fail on invalid input units', function () {
assert.throws(function () {
Units.convert('1', 'random', 'wei')
}, /^Error: Unsupported input unit$/)
})
it('should fail on invalid output units', function () {
assert.throws(function () {
Units.convert('1', 'wei', 'random')
}, /^Error: Unsupported output unit$/)
})
})

describe('lazyConvert', function () {
Expand All @@ -23,6 +33,15 @@ describe('lazyConvert', function () {
assert.equal(Units.lazyConvert('1 finney', 'eth'), '0.001 eth')
assert.equal(Units.lazyConvert('20 gwei', 'eth'), '0.00000002 eth')
})
it('should fail on invalid input', function () {
assert.throws(function () {
Units.lazyConvert('1')
}, /^Error: Invalid input$/)

assert.throws(function () {
Units.lazyConvert('1 eth wei')
}, /^Error: Invalid input$/)
})
})

describe('units export', function () {
Expand Down

0 comments on commit d74134a

Please sign in to comment.