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

Please consider an API that is more consistent with sinon #75

Closed
TauPan opened this issue Jan 23, 2018 · 5 comments
Closed

Please consider an API that is more consistent with sinon #75

TauPan opened this issue Jan 23, 2018 · 5 comments

Comments

@TauPan
Copy link

TauPan commented Jan 23, 2018

Hi!

I've just found out about this while searching for a workaround for sinonjs/sinon#1265

This repairs my tests after switching from a factory function to ES6 classes, however I notice that the API you offer is inconsistent with the way stubs are generally used in sinon.

That, or maybe someone could implement the sinon ticket (which is way over my head). ;)

@lukastaegert
Copy link
Member

Not sure in how far I can accommodate you here due to time constraints on my side but—what would be a more consistent API that satisfies everything we can do right now, e.g. track instances, allow for custom post-processing code etc.?

@TauPan
Copy link
Author

TauPan commented Jan 24, 2018

Ok. I have time constraints as well and sinon-helpers has helped me a great deal! Thanks!

I can't sketch the full API but some points strike me as odd compared to sinon:

  • I'd expect a StubConstructor to have methods as attributes which are stubs (or have a similar api), so that I can call returns on the stubbed method (instead of returning(...))
  • I believe in the sinon API I would access e.g. "returnValues" of a function call, which I guess could apply to the constructor as well (instead of getInstances).

But on the other hand I hope that sinon-helpers is just a temporary measure and sinon will support ES6 classes in the nearer future, so feel free to close this if priorities mandate, as unfortunately I won't be able to help with the implementation.

@lukastaegert
Copy link
Member

I finally found some time to rework things. I got rid of returning in favour of withInit (which is basically a new name for afterCreation). Also, you can now access instances directly via .instances and constructor arguments via .args, much more similar to sinon. I hope this improves this library somewhat on this front. I did not implement method stubbing directly on the constructor as this is already reserved for static class methods.

Feel free to open a new issue if you have more ideas.

@TauPan
Copy link
Author

TauPan commented Nov 5, 2018

Looks good to me, thanks! I'll try to migrate to v2 when I next have to touch the stubbed tests.

@lukastaegert
Copy link
Member

👍 Should also be a little faster now with reduced memory footprint and no longer has any dependencies

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

No branches or pull requests

2 participants