Closed darcyrush closed 1 year ago
Thinking about what you actually want to achieve with this, a function that throws a primitive, you actually already have this today:
const s = sinon.stub().throws(() => 42)
s();
> Uncaught 42
So I do not see the need to expand the API further :)
Is your feature request related to a problem? Please describe. Javascript has some warts where
throw 123
orthrow 'string'
is completely legal, and recent TypeScript hints at this with Error cause types being defined asunknown
Currently
stub().throws(123)
throws a number, butstub().throws('string')
throws an Error object named 'string'.Describe the solution you'd like A function to throw a non object (string)
Describe alternatives you've considered Personally I prefer and use the more explicit version of
stub().throws(new Error(string))
but its not feasible to changestub().throws('string')
to actually throw a string due to backwards compatibility, so I think a new function would be beneficial