mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-04-08 20:04:14 +00:00
Remove unused error.handleCallback function
This commit is contained in:
parent
a6282d2b28
commit
f94be29047
@ -21,11 +21,3 @@ exports.handle = (error, exit = true) ->
|
||||
errorCode = 1
|
||||
|
||||
process.exit(errorCode) if exit
|
||||
|
||||
exports.handleCallback = (callback, context, exit) ->
|
||||
if not _.isFunction(callback)
|
||||
throw new Error('Callback is not a function')
|
||||
|
||||
return (error, args...) ->
|
||||
exports.handle(error, exit) if error?
|
||||
return callback.apply(context, args)
|
||||
|
@ -77,52 +77,3 @@ describe 'Errors:', ->
|
||||
checkProcessExitOption error, false, (processExitStub, logErrorStub) ->
|
||||
expect(logErrorStub).to.have.been.calledOnce
|
||||
expect(logErrorStub).to.have.been.calledWith('No such file or directory: hello')
|
||||
|
||||
describe '#handleCallback()', ->
|
||||
|
||||
it 'should throw an error if callback is not a function', ->
|
||||
expect ->
|
||||
errors.handleCallback('hello')
|
||||
.to.throw('Callback is not a function')
|
||||
|
||||
it 'should return a new function', ->
|
||||
callback = errors.handleCallback(_.noop)
|
||||
expect(callback).to.be.an.instanceof(Function)
|
||||
|
||||
describe 'given no error', ->
|
||||
|
||||
it 'should pass arguments back to the callback', ->
|
||||
spy = sinon.spy()
|
||||
callback = errors.handleCallback(spy)
|
||||
callback.call(null, null, 'Hello World', 123)
|
||||
expect(spy).to.have.been.calledOnce
|
||||
expect(spy).to.have.been.calledWithExactly('Hello World', 123)
|
||||
|
||||
it 'should be able to pass a context', ->
|
||||
spy = sinon.spy()
|
||||
context =
|
||||
foo: 'bar'
|
||||
callback = errors.handleCallback(spy, context)
|
||||
callback.call(null, null, 'Hello World', 123)
|
||||
expect(spy).to.have.been.calledOn(context)
|
||||
|
||||
describe 'given an error', ->
|
||||
|
||||
beforeEach ->
|
||||
@handleStub = sinon.stub(errors, 'handle')
|
||||
@error = new Error('hello')
|
||||
|
||||
afterEach ->
|
||||
@handleStub.restore()
|
||||
|
||||
it 'should call handle() with the error', ->
|
||||
callback = errors.handleCallback(_.noop)
|
||||
callback.call(null, @error)
|
||||
expect(@handleStub).to.have.been.calledOnce
|
||||
expect(@handleStub).to.have.been.calledWith(@error)
|
||||
|
||||
it 'should call handle() with the exit boolean parameter', ->
|
||||
callback = errors.handleCallback(_.noop, null, false)
|
||||
callback.call(null, @error)
|
||||
expect(@handleStub).to.have.been.calledOnce
|
||||
expect(@handleStub).to.have.been.calledWithExactly(@error, false)
|
||||
|
Loading…
x
Reference in New Issue
Block a user