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

Spying on property? #1723

Closed
natanavra opened this issue Mar 4, 2018 · 3 comments
Closed

Spying on property? #1723

natanavra opened this issue Mar 4, 2018 · 3 comments

Comments

@natanavra
Copy link

Is it possible to spy on properties without ES6 getters/setters?
e.g.:

let obj = {settings: {key: 'value'};
sinon.spy(obj);
sinon.assertTrue(obj.settings.key.called);
@natanavra natanavra changed the title Spying on property Spying on property? Mar 4, 2018
@Alexsey
Copy link
Contributor

Alexsey commented Mar 8, 2018

getters/setters are ES5 and yes, you have an option - use Proxy from ES6. But Sinon can help you here only by providing a spy that you can put in the getter to assert it later. Because spys, stubs and mocks are only for functions. That is because unit testing don't imply that you should ever spy on properties

@natanavra
Copy link
Author

natanavra commented Mar 8, 2018

OK, thanks.
I was looking for a way to check if certain properties are being "used" by a function, something like a "litmus check"

@mroderick
Copy link
Member

It IS possible to spy on getters/setters ... unfortunately, it hasn't been documented yet.

See #1606 for a solution

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

3 participants