Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fatso83 opened this issue Aug 8, 2016 · 6 comments
Open

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

fatso83 opened this issue Aug 8, 2016 · 6 comments

Comments

@fatso83
Copy link
Contributor

fatso83 commented Aug 8, 2016

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

#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

#831 (comment)
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

#1832
Why: Often asked for. Needs extra tools (esm).

Stubbing instance methods

#878 (comment)

Cannot stub arrow function in a class #1136

#1136 (comment)

@fatso83 fatso83 self-assigned this Aug 8, 2016
@fatso83 fatso83 modified the milestones: 2.1, New sinon.org Aug 8, 2016
@daprahamian
Copy link

👍

@fatso83
Copy link
Contributor Author

fatso83 commented Mar 23, 2017

No time yet, but for people coming here please read the comment thread in 831 and see if it covers the info on what you are trying to do. Alternatively this or this.

@adityarawat007
Copy link

@fatso83 can you please assign me this issue

@fatso83
Copy link
Contributor Author

fatso83 commented Oct 12, 2024

Hi, @adityarawat007 . Thanks for volunteering. It's an old, but important issue. I have done a lot of the ground work here in the article I published on sinonjs.org called "Case study: real world dependency stubbing" that deals with the tooling aspects when using stuff like Typescript and the SWC bundler/transpiler. I also show three different approaches for achieving the same objective, where one is using module loading interceptors (targeting link seams) like Quibble (a modern alternative to Proxyquire). So that should partly cover these two cases:

It does not at all cover how ES6 / ES2015+ classes are similar and dissimilar to how one created classes in ES5 and earlier, including how the prototype can be manipulated and such. So covering that, and the other points:

  • Stubbing instance methods
  • "cannot stub arrow function in a class"
    etc

Should be very nice to get!

@fatso83 fatso83 assigned fatso83 and adityarawat007 and unassigned fatso83 Oct 12, 2024
@fatso83
Copy link
Contributor Author

fatso83 commented Oct 13, 2024

@adityarawat007 What you need to fire up the docs is in the /docs folder. Shout out if you need some help in getting up and running or want to discuss more in detail what to write!

@adityarawat007
Copy link

Thanks alot @fatso83 for assigning me this issue. I will surely get back to you if I will need any help or support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants