How can we override reject creating a new Error Object?
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 809
- PR merge metrics
- No merged PRs in 30d
Description
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
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at lib/sinon/default-behaviors.js#L176 and trace how rejects handles the supplied value when using a configured promise implementation. Compare that behavior with the native Promise.reject and Bluebird examples in the issue; done means a rejected string remains the original string rather than becoming an Error object, with regression coverage for the behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100