Not allowed to define a non-configurable property on the WindowProxy object #1195

Open
lidel opened this Issue Nov 23, 2016 · 0 comments

Projects

None yet

1 participant

@lidel
lidel commented Nov 23, 2016 edited

What did you expect to happen?

I should be able to stub global functions via stub method under every browser:

sinon.stub(window, 'myFunction')

What actually happens

Stubbing with above syntax fails under Firefox 51 with error:

Not allowed to define a non-configurable property on the WindowProxy object
       wrapMethod@node_modules/sinon/pkg/sinon.js:1380:17
       stub@node_modules/sinon/pkg/sinon.js:3446:20
       stub@node_modules/sinon/pkg/sinon.js:4187:33

My guess: Object.defineProperty on window with non-configurable property throws exception.

This is probably caused by recent changes to Window and WindowProxy:

Firefox is the first browser to implement this spec, but my understanding is that other browsers will follow at some point. This means the mentioned error is here to stay and needs to be fixed sooner or later.

Other resources discussing the WindowProxy change in depth (W3C/Mozilla):

How to reproduce

Download Firefox 51 or later (eg. from https://www.mozilla.org/en-US/firefox/developer/).
Try to run basic test with sinon.stub(object,'method')

This will fail:

sinon.stub(window, 'myFunction')

But this will work fine:

var oldMyFunction = window.myFunction; // backup original function for later
window.myFunction = sinon.stub(); // overwrite function with anonymous stub
// [do tests with stub here]
window.myFunction = oldMyFunction; // restore original function

So.. we have a workaround.
It seems some kind of fix for stub(obj, method) needs to applied to work with WindowProxy.

If "real life" example is needed, this line from my pet project produces error under Firefox 51 (with stacktrace), but works fine under Firefox 49.

This is my first report here, please let me know if I can provide any additional information.

@lidel lidel referenced this issue in lidel/ipfs-firefox-addon Nov 23, 2016
Open

Fix unit tests under Firefox Nightly #174

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