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
Improve docs for fakes #2070
Comments
Fakes definitely need better docs. Maybe something to address in the proposed (still undecided, @mroderick?) October hackathon? |
@fatso83 I would like to have a go at this. Would I be updating the file https://github.com/sinonjs/sinon/blob/master/docs/release-source/release/fakes.md ? Also is the scope of this issue to define which functions are available on a mock object, maybe linking to the spy and stub documentation? |
@peterjgrainger That's great! The scope and that approach seems reasonable ... |
Looking at the code fakes seem to have the same API as a Spy and nothing from a Stub. Propose updating the docs to remove the reference to stubs as it is a little misleading and adding that the API of fakes is the same as a spy Shout 😮 if that doesn't look correct. |
@peterjgrainger Thanks for looking into this. I can see similarities from |
@mshaaban0 thanks for the input. I'll take a closer look |
@fatso83 @mshaaban0 I think I misunderstood the scope. I thought this ticket covered documentation of the fake function e.g.
not directly on the fake itself i.e.
From what I can see
@itmayziii seems to be referring to I think I understand what to do now. Alter the current documentation to say which static functions are inspired by a spy and which are inspired by a stub and change the wording |
You're not the only one to misunderstand the scope. Glad you cleared it up for us 😄 |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What is needed to be done in this issue? If someone makes it clearer I would like to make a contribution. Since there is a section called Thanks 😊 |
@srknzl TBH, I do not remember all that well, but these are some points that could need improvement:
|
While this is true, I think using a spy instead of a fake + replace call is easier. Is there anything that can be done about this? const foo = {bar: () => {}};
const aSpy = sinon.spy(foo, 'bar');
foo.bar();
console.log(aSpy.called); // true vs const foo = {bar: () => {}};
const barFake = sinon.fake(foo.bar);
sinon.replace(foo, 'bar', barFake);
foo.bar();
console.log(barFake.called); // true If it was as easy as spies, fakes would be the only one that I'll use. Edit: I found out that I can do this: const foo = {bar: () => {}};
sinon.replace(foo, 'bar', sinon.fake(foo.bar));
foo.bar();
console.log(foo.bar.called); // true might worth to document this usage as well. |
@srknzl I am not sure if the replace call returns anything, but it could potentially return the fake. That would make it a bit smoother. |
Just verified: f = sinon.fake();
val=sinon.replace(o, 'b', f)
assert.equal(f,val); meaning you can write this: const foo = {bar: () => {}};
const fake = sinon.replace(foo, 'bar', sinon.fake());
foo.bar();
console.log(fake.calledOnce); // true |
yeap, makes sense. Also replace() does not state its return value on sandbox page |
Just make it clear, which versions should change? All the versions that has fake, right? Or just the next version? |
Initial pr is at #2360, work in progress. I am waiting for your feedback. |
Is your feature request related to a problem? Please describe.
Reading through what a fake can and can not do is not clear from the documentation.
Describe the solution you'd like
Exact methods that are available to a Fake need to be documented.
First of all thank you for Sinon, I believe the library is powerful and has helped me write a lot of tests. What I'm requesting here is that Fakes need their documentation improved. Here is an example of something I struggled with.
The first sentence of the Fakes documentation says:
The word "merges" here is too loosely defined to know what the API of a fake ends up being. My conclusion is that fakes seem to share an API with Spies with some additional stubbing behavior similar to stubs. I came to this conclusion because it seems that the fake object has the property
called
like a spy does (can't find this documented anywhere except in spies documentation), andwithArgs
that is usually available to stubs but does not seem available to fakes.The text was updated successfully, but these errors were encountered: