I'm trying to test the message of an Error using expect().to.throw. I read that expect needs to be passed a function to execute, as oppose to the function that returns. Anyways, I still can't seem to get this to work, I've tried a number of variations, but this is the basic setup in jsfiddle. Any ideas why this won't work or how can I fix it?
Thank you
The issue was that I was using throw to check, but I wasn't actually throwing an error, but returning an Error. The following evaluates correctly:
expect(test.throwFunction()).to.be.an.instanceOf(Error).with.property('message', 'This is an error message')
However, I'm not sure this is the cleanest way to check - seems like there could be a shorthand version.
Update: Looks like there's a work in progress for adding to.be.an.error
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With