-
-
Notifications
You must be signed in to change notification settings - Fork 768
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
Add propertyStub #161
Comments
The reason this does not already exist is because stubbing a property is as easy as You can do this today if you're working through a sandbox object. The reason property stubbing is available only in sandboxes, is that they can be automatically reverted, which provides some sort of convenience. |
Didn't know the is property stubbing for sandboxes! How can I use it? |
Like so:
|
I think this behavior would be useful at least in one particular case: stubbing |
Hi @avand, built in browser globals, like var urlUtils = {}
urlUtils.setLocation = function (value) {
window.location = value
}
// in your test code
sinon.stub(urlUtils, 'setLocation') |
Is it impossible for Sinon to stub an object's properties? Or is the issue
|
@avand Sinon can stub properties (using the sandbox feature). It can also stub globals, if they are user defined. Sinon can not stub some special browser built-ins, for example the |
A little late jumping in, but you can work around some use cases for stubbing location with history.replaceState(), which doesn't trigger any reloads. Just be sure to restore the correct URI after your tests are finished. So in your test, something like:
There's no way to block code that directly sets properties on 'location', so if something does a |
Currently, we have a method stub, so we can stub an object's method, and if that object doesn't have this method or its name changes, sinon throws an exception.
Some of my tests are depended on object's property, which I want to also stub and to have the same failure mechanism as methods stub have.
Why property stubs you ask? I use it to test things like bindings and such.
Is there a reason not to add it? do you have a proposal on how to implement it? (I don't mind creating the PR myself, just wanted to get a second opinion).
Thanks,
Shai
The text was updated successfully, but these errors were encountered: