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
Make spy properties non-enumerable #1936
Comments
How would this affect REPL usage and API discoverability? One of my favorite ways of using new tech is through exploratory testing on the REPL. Doing |
Yes, non-enumerable properties are still shown on tab autocomplete in Node.js REPL. |
I think this would be a good improvement, and can't currently think of any downsides. |
This has been implemented with #1941 and released as |
Thanks for this! However I do not think this worked: > sinon.spy()
{ [Function: proxy]
isSinonProxy: true,
called: false,
notCalled: true,
calledOnce: false,
calledTwice: false,
calledThrice: false,
callCount: 0,
firstCall: null,
secondCall: null,
thirdCall: null,
lastCall: null,
args: [],
returnValues: [],
thisValues: [],
exceptions: [],
callIds: [],
errorsWithCallStack: [],
displayName: 'spy',
toString: [Function: toString],
instantiateFake: [Function: create],
id: 'spy#0' }
> Object.keys(sinon.spy())
[ 'isSinonProxy',
'called',
'notCalled',
'calledOnce',
'calledTwice',
'calledThrice',
'callCount',
'firstCall',
'secondCall',
'thirdCall',
'lastCall',
'args',
'returnValues',
'thisValues',
'exceptions',
'callIds',
'errorsWithCallStack',
'displayName',
'toString',
'instantiateFake',
'id' ] Those keys are still enumerable. As a consequence the original problem still arises. |
@ehmicky which version of |
I am using Sinon |
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. |
Bumping because this issue is still valid with Sinon |
Ah, @LouisBrunner explicitly just made the functions non-enurable. The other non-function properties are still enumerable. Don't you still want to see those props? |
Here you go: #1975 Ended up being more than one place to modify. |
Is your feature request related to a problem? Please describe.
When a Sinon spy assertions fails during unit testing, some assertion libraries like
power-assert
(used by Ava) will print all the spy properties (including the spy methods) which is very verbose and makes it harder to see why the test failed.Describe the solution you'd like
Make Sinon-specific spy properties non-enumerable.
Describe alternatives you've considered
power-assert
but it's hard to do from Avapower-assert
for this casespy[Symbol.toStringTag]
orspy.toJSON()
but this does not work sincepower-assert
does not use either. Instead it iterates over enumerable properties.Additional context
The feature request is about spies, but it most likely can be related to other Sinon objects, such as stubs and fakes.
Here's a screenshot of how verbose a single test Sinon assertion can become with Ava:
The text was updated successfully, but these errors were encountered: