Node assert.throws not catching exception

前端 未结 4 727
死守一世寂寞
死守一世寂寞 2020-12-15 03:49

Given this code:

var assert = require(\'assert\');

function boom(){
    throw new Error(\'BOOM\');
}

assert.throws( boom(), Error );

I ge

4条回答
  •  离开以前
    2020-12-15 04:18

    You can use bind():

    assert.throws( boom.bind(null), Error );
    

    With arguments it is:

    assert.throws( boom.bind(null, "This is a blowup"), Error );
    

提交回复
热议问题