-
Notifications
You must be signed in to change notification settings - Fork 3
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
Privatized stamp with stubs/fakes #47
Comments
Hello there! 👋 For now I'd like to share what happened to me since I started doing stamps. I used to use sinon a lot. Until I met stamps. Since then I do not use sinon. When my projects are using stamps the sinon is not needed. There are two quick solutions though.
const exampleStamp = stampit.compose(Configure.noPrivatize())
.methods({ myMethod() { return true; } });
let called = 0;
exampleStamp.methods({ myMethod() {
called += 1;
return false;
} });
const stubbedStampInstance = stubbedStamp();
const stubbedMethodResult = stubbedStampInstance.myMethod();
console.log(called); // 1 If none of the above suffice feel free to ask further. |
Understood that I could write my own equivalent of Sinon, but then I am re-writing a ton of assertions, especially if I want to assert against calledWith etc. This is a more general problem with the Privatize stamp in that you cannot access ANY properties on public functions due to the method of proxying, my Sinon use case is just the first one I ran into :) |
I hope to rewrite the |
@MaximusHaximus I use next pattern:
P.S. hehe, what an encounter, brother. |
Looks like the This would allow privatizing only the necessary properties, not all of them! |
Howdy,
I'm running into some problems with stubbing methods on stamps that have been privatized. In particular, because referencing the injected method always references the PROXY function, there's no way to access the stubs properties. It'd be nice to be able to reference the stubs on their location since they are not private-ized and it's counter intuitive to not be able to access properties on the public methods. Not sure the best way to go about achieving that goal. For now I am storing my stubs in a local closure, then referencing them from their local closure variables. It'd be nicer to be able to reference the functions directly on the object. Open to any alternative composition patterns too, if there's a better way to accomplish this.
The text was updated successfully, but these errors were encountered: