1 Star 0 Fork 0

animalcoder/Vue

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
index.coffee 1.11 KB
一键复制 编辑 原始数据 按行查看 历史
animalcoder 提交于 2020-03-17 14:52 +08:00 . Vueinit
{ 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
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/animalcoder/Vue.git
git@gitee.com:animalcoder/Vue.git
animalcoder
Vue
Vue
master

搜索帮助