-
-
Notifications
You must be signed in to change notification settings - Fork 769
Exception when restoring methods under phantomjs #306
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
Comments
To add some context: Sinon has two ways of stubbing and the corresponding reverse operation:
In your case, Sinon is apparently using the second approach to stub the Just putting a try-catch around it will leave the stub in place which is not really solving your problem. I'm wondering whether this is produceable in other (WebKit) browsers? |
It doesn't seem to leave the stub in place since the lines below will check On Thu, Jul 18, 2013 at 1:10 PM, Maximilian Antoni <[email protected]
Giuliano Barberi |
Found similar problem when stubbing localStorage.getItem.
@giulianob Did you find any workaround or more info about this behaviour? |
Oh, found the problem. You can use standard JS access to get/set the properties, like:
So in FF, you can actually store a property called "getItem"
|
bump on this ! I cannot What do ? |
I'm not sure what to do about this. Looking at @scinos comment, it seems this may not be possible to solve in a satiesfactory way? Would it work to |
Not sure what to do here. I would suggest not stubbing directly on native objects. Please re-open if you feel there is something Sinon can do to help you here. |
Cannot restore sinon spies in phantom js. But it's working fine in chrome |
+1 |
Could you describe your setup or share code to reproduce the issue?
|
When running our tests in phantomjs, we're seeing an exception that gets thrown when sinonjs is restoring sessionStorage.getItem method. It happens at the following "delete" call:
After some research, it appears that delete will throw exceptions when javascript is running in strict mode if it's unable to delete a property. From Mozilla's page: "Third, strict mode makes attempts to delete undeletable properties throw (where before the attempt would simply have no effect):" In Chrome, when we delete sessionStorage.getItem after it's wrapped it simply sets it back to the native implementation. In Phantom, it throws an exception if it's unable to delete. It looks like the comment above already expects cases where the delete fails and the method needs to be restored manually but it doesnt expect cases where the delete throws an exception.
Would it be possible to add a try/catch around the delete for strict browsers?
The text was updated successfully, but these errors were encountered: