sinonjs / sinonjs/sinon

Feature Request: Add API support to stub a parent class constructor.

Open
#2,578 5 comments 0 reactions 0 assignees View on GitHub

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

  1. @fatso83 provides a solution here in plain JavaScript.
  2. Perhaps the API of sinon.createStubInstance could 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.