I use ES2015 with babel stage-2 preset, and if you do so, you can use this as well.
I took @StephenM347 solution and modified it a little to be shorter an even more readable IMHO :
let expectCalling = func => ({ withArgs: (...args) => expect(() => func(...args)) });
Usage :
expectCalling(handleError).withArgs(true).to.not.throw();
expectCalling(handleError).withArgs("anything else").to.throw("stop js execution");
Note: if you wish the same usage (and stick to use expect()
as is) :
let calling = func => ({ withArgs: (...args) => () => func(...args) });