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

sinon fails when restoring stubbed properties in window object in IE11 #1881

Closed
pavelkornev opened this issue Aug 22, 2018 · 5 comments
Closed

Comments

@pavelkornev
Copy link

Describe the bug
it's possible to stub, but not to restore some properties in window object in IE11 causing sinon to throw a type error: TypeError: Cannot redefine non-configurable property '...'

To Reproduce
https://jsbin.com/qixexucasa/edit?js,console,output - compare behaviour in IE11 and any other browser.

"TypeError: Cannot redefine non-configurable property 'parent'
   at restore (https://unpkg.com/sinon@6.1.5/pkg/sinon.js:3253:13)
   at Global code (https://null.jsbin.com/runner:18:1)"

Expected behavior
In IE11 certain properties of window object are non-configurable, but it's still possible to stub them and this is quite useful in the tests. The expectable behaviour would be one of those:

  1. sinon should throw an error on the stub step (not on the restore() step) that it's not possible to stub this property;
  2. when stubbing the property sinon should not copy the original configurable attribute, is there any reason for this? In case of false value sinon just creates problems for itself, so it's not possible to restore it. So this line should be always true:
    configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)

Context:

  • Library version: all versions are affected, tested in 4.4.6 & 6.1.5.

Please confirm whether it's a bug or an expected behaviour.

openui5bot pushed a commit to SAP/openui5 that referenced this issue Aug 22, 2018
….stub.value() bug

More details: sinonjs/sinon#1881

Change-Id: Iaad8c012f34cf2c6a808d3c4ca977cbf9a3ad024
BCP: 1870331288
openui5bot pushed a commit to SAP/openui5 that referenced this issue Aug 23, 2018
….stub.value() bug

More details: sinonjs/sinon#1881

CR-Id: 002075125800003075332018
Change-Id: Iaad8c012f34cf2c6a808d3c4ca977cbf9a3ad024
BCP: 1870331288
(cherry picked from commit ba9b797)
@mroderick
Copy link
Member

Thank you for your detailed description of the issue.

Would going with the second strategy actually make this work in IE11? If so, that would be my preference.

Would you be up for contributing a pull request to make the necessary changes?

@stale
Copy link

stale bot commented Oct 26, 2018

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.

@stale stale bot added the stale label Oct 26, 2018
@stale stale bot removed the stale label Oct 26, 2018
@stale
Copy link

stale bot commented Dec 26, 2018

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.

@stale stale bot added the stale label Dec 26, 2018
@stale stale bot closed this as completed Jan 2, 2019
@mroderick mroderick reopened this Jan 2, 2019
@stale stale bot removed the stale label Jan 2, 2019
@XxshiftxX
Copy link

XxshiftxX commented Feb 17, 2020

I having same problem and I found cause of this on sinon/default-behaviors.js line 258.

value: function value(fake, newVal) {
    var rootStub = fake.stub || fake;

    Object.defineProperty(rootStub.rootObj, rootStub.propName, {
        value: newVal,
        enumerable: true,
        configurable: isPropertyConfigurable(rootStub.rootObj, rootStub.propName)
    });

    return fake;
}

I don't know why it should follow original object's configurable option. I think it have to be always true because After it stubed, it can be restored or rewritten (typically sinon.restore()) regardless of original object's option.

Temporarily I fixed this problem by changing that code always return true.

@fatso83
Copy link
Contributor

fatso83 commented Aug 11, 2023

We haven't supported IE11 in years, so this will not be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants