-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
[@types/sinon] sinon.spy lacks the third argument #32398
Comments
Is this an undocumented feature? I don't see it here: https://sinonjs.org/releases/v7.2.3/spies/#creating-spies-sinonspy-method-signatures Generally, we only add typings of features that are documented. |
It is undocumented. I suggest opening an issue with sinon to find out if it's supported (as in they won't just remove it one day and it isn't deprecated). |
OK. I issued. |
It's supported though still undocumented. |
Cool, feel free to create a PR (for both sinon 🚀 and definitely typed 🚀 ) |
Is that documentation guarding? |
Oh, I found this fix is incomplete! If In example: const descriptor = sinon.spy(RGBColor.prototype, 'red', ['set', 'get']);
const color = new RGBColor();
color.red = 128;
expect(descriptor.set.callCount).toBe(1); I'd like to have official documentation. |
All the line you linked to is doing is setting the descriptor config (as opposed to an empty, default descriptor). This is just so it sets the getter/setter correctly through the property descriptor. It should just return a spy like any other spy call. Your example works because sinon returns the wrapped method, which in this case is just the property descriptor its self. |
Ah, you mean a return value should have the type of the original method, property descriptor in this case, instead of just a callable, then? EDIT: And set/get of those properties must be |
alright so the short explanation to this is that sinon does some hacky things when you spy on something. behind the scenes, it just attaches a bunch of sinon things to the property descriptor. the descriptor is usually we can't easily represent this in strong types, though... its doable in some way i imagine but could lead to unnecessary complexity. if its wanted enough, someone should take a stab at it but otherwise i'd personally leave it out (and somehow work around it). |
Agree. The typing would be hard and complex. Can I show my image by code bellow? I know the descriptor is just a definition, but I can't grab the final type of that execution pass. |
If you know how to fix the issue, make a pull request instead.
@types/sinon
package and had problems.Definitions by:
inindex.d.ts
) so they can respond.If you do not mention the authors the issue will be ignored.
We can't spy accessors because the current definition of
sinon.spy
lacks third argument calledtypes
, which should be typed astypes?: string[]
.See https://github.com/sinonjs/sinon/blob/master/lib/sinon/spy.js.
My test project is here: https://codesandbox.io/s/92n50m2n1p.
The text was updated successfully, but these errors were encountered: