sinonjs / sinonjs/sinon

Create an article on how ES2015 classes relate to stubbing/spying

Open
#1,121 6 comments 13 reactions 1 assignee View on GitHub

@adityarawat007 is already working on this.

Since Oct 12, 2024.

Documentation ES2015+ hacktoberfest Help wanted pinned
Dominant language
JavaScript
Stars
9.8k
Forks
809
PR merge metrics
No merged PRs in 30d

Description

A couple of issues with a huge pile of comments shows there is some confusion as to how (if at all possible) one can stub constructors in ES6/ES2015 classes. This has been answered in the comments, but it should be expanded to an article showing what can and cannot be done.

Compiled it down to this list of issues/links (from here), which can serve as the basis for one or more articles. Also, this search could prove useful.

Show how to stub ES6 constructor #1265

https://github.com/sinonjs/sinon/issues/1265
What: Feature request to automatically call stubbed/spied constructors with new.
Why: Often asked for. People get confused about Function#constructor and the constructor keyword.
Should either make a small tutorial to document how to "stub" (make a new) constructor
and/or introduce a small Sinon NPM plugin to do so (in the article).

ES6 classes and stubbing out dependencies using proxyquire

https://github.com/sinonjs/sinon/issues/831#issuecomment-209648966
https://gist.github.com/fatso83/329da40002d45533b1e74db825f2bf54
What: how to use proxyquire to intercept dependencies
Why: often asked for

Document how to configure Node to allow stubbing EcmaScript modules #1832

https://github.com/sinonjs/sinon/issues/1832
Why: Often asked for. Needs extra tools (esm).

Stubbing instance methods

https://github.com/sinonjs/sinon/issues/878#issuecomment-250198255

Cannot stub arrow function in a class #1136

https://github.com/sinonjs/sinon/issues/1136#issuecomment-244608044

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.