選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.coffee 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. { iferr, tiferr, throwerr } = require '../index.coffee'
  2. { equal: eq, throws } = require 'assert'
  3. invoke_fail = (cb) -> cb new Error 'callback error'
  4. invoke_succ = (cb) -> cb null
  5. throw_error = -> throw new Error 'thrown'
  6. describe 'iferr', ->
  7. it 'calls the error callback on errors', (done) ->
  8. invoke_fail iferr(
  9. (err) ->
  10. eq err.message, 'callback error'
  11. do done
  12. ->
  13. done new Error 'shouldn\'t call the success callback'
  14. )
  15. it 'calls the success callback on success', (done) ->
  16. invoke_succ iferr(
  17. -> done new Error 'shouldn\'t call the error callback'
  18. done
  19. )
  20. describe 'tiferr', ->
  21. it 'catches errors in the success callback', (done) ->
  22. invoke_succ tiferr(
  23. (err) ->
  24. eq err.message, 'thrown'
  25. do done
  26. throw_error
  27. )
  28. describe 'throwerr', ->
  29. it 'throws errors passed to the callback', (done)->
  30. try invoke_fail throwerr ->
  31. done 'shouldn\'t call the success callback'
  32. catch err
  33. eq err.message, 'callback error'
  34. do done
  35. it 'delegates to the success callback otherwise', (done) ->
  36. invoke_succ throwerr done