Feature Request: Add API support to stub a parent class constructor.
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 9.8k
- Forks
- 809
- PR merge metrics
- No merged PRs in 30d
Description
Is your feature request related to a problem? Please describe.
I've seen a lot of questions asking how to stub a parent class's constructor. @fatso83 provides a solution here, but it is written in plain JavaScript. Unless you are searching the sinon github repository, this solution is hard to find.
It's written in vanilla js, meaning the prototype's lifecycle must be managed by the developer: they have to undo the Object.setPrototypeOf change or the child class's prototype will remain modified, causing test pollution.
Describe the solution you'd like
I would like sinon to provide a way to stub a parent class constructor with its API. That way, sinon can manage the prototype lifecycle like it manages other test double lifecycles.
Describe alternatives you've considered
- @fatso83 provides a solution here in plain JavaScript.
- Perhaps the API of
sinon.createStubInstancecould be expanded to support this use case?
Additional context
- #1892
- I may be able to submit a PR for this, but I would like some guidance on how to name the new API.
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 by reading the linked discussion in #1892 and the proposal to expand sinon.createStubInstance. The issue needs an API design and naming decision before implementation can begin; done would mean a supported parent-constructor stubbing API that manages prototype cleanup within Sinon’s test-double lifecycle.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100