| Server IP : 185.208.173.17 / Your IP : 87.236.161.98 Web Server : Microsoft-IIS/10.0 System : Windows NT SRV8576125506 10.0 build 26100 (Windows Server 2016) AMD64 User : IUSR ( 0) PHP Version : 7.4.13 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/parsmega.nuxt/node_modules/iferr/test/ |
Upload File : |
{ iferr, tiferr, throwerr } = require '../index.coffee'
{ equal: eq, throws } = require 'assert'
invoke_fail = (cb) -> cb new Error 'callback error'
invoke_succ = (cb) -> cb null
throw_error = -> throw new Error 'thrown'
describe 'iferr', ->
it 'calls the error callback on errors', (done) ->
invoke_fail iferr(
(err) ->
eq err.message, 'callback error'
do done
->
done new Error 'shouldn\'t call the success callback'
)
it 'calls the success callback on success', (done) ->
invoke_succ iferr(
-> done new Error 'shouldn\'t call the error callback'
done
)
describe 'tiferr', ->
it 'catches errors in the success callback', (done) ->
invoke_succ tiferr(
(err) ->
eq err.message, 'thrown'
do done
throw_error
)
describe 'throwerr', ->
it 'throws errors passed to the callback', (done)->
try invoke_fail throwerr ->
done 'shouldn\'t call the success callback'
catch err
eq err.message, 'callback error'
do done
it 'delegates to the success callback otherwise', (done) ->
invoke_succ throwerr done