-
-
Notifications
You must be signed in to change notification settings - Fork 777
Open
Milestone
Description
sinon/lib/sinon/default-behaviors.js
Line 176 in 4310343
| if (typeof error === "string") { |
I'm maintaining some code that rejects strings and this is creating issues while testing. my bluebird catches are not behaving correctly.
bluebird.rejects('Something')
.catch(e => e === 'Something' /* true */, () => console.log(typeof e) /*string*/)
.catch(() => console.log('should not be here'));However using sinon.stub().usingPromise('bluebird').rejects('Something'); ends up creating an error object with the name Something. Not expected at all.
Before someone says we are only supporting native Promises, let's investigate what they do!
Promise.reject('Something')
.catch(e => {
console.log(e === 'Something'); // true
console.log(typeof e); // string
});Hmmm, they don't create an Error class, they just toss the exception it was given like a throw.
try {
throw 'Something';
} catch (e) {
console.log(e === 'Something'); // true
console.log(typeof e); // string
}