Closed eugenet8k closed 1 year ago
Yup, seeing the descriptor is non-configurable, so need to look into the previous version to understand how this could have worked before.
Found the issue. Previously we the object descriptor was pretty much left unchanged (apart from the value
prop), but leaving configurable: false
on a stub would make it impossible to remove, so this was added in 15.0.4 to make it possible to create stubs that would shadow a method on the prototype.
Unfortunately, it introduced a regression for cases where the object descriptor was not from the prototype, but the object itself. If configurable
is false then it cannot be changed back into something else, which is why it throws. Will add a regression test and fix asap with a check for isOwn
before modifying the descriptor.
The sandboxes were fine, but I was unable to get them running locally as unit tests as they depended on window existing. If you want to test out the fix in #2515 and see that it fixes your issue, you can just have a look at the diff and copy it manually into the right section (the line it fails) in node_modules/sinon/pkg/sinon-esm.js
:
- methodDesc.configurable = true;
+
+ // you are not allowed to flip the configurable prop on an
+ // existing descriptor to anything but false (#2514)
+ if (!owned) {
+ methodDesc.configurable = true;
+ }
+
@fatso83 yes, the fix works well for our case, thank you!
Out as Sinon 15.1.0 (minor due to also getting the new clock.jump() method)
Describe the bug After https://github.com/sinonjs/sinon/pull/2508 was merged and the new sinon v15.0.4 is published a lot of code in our project stopped working. We can an error when trying to stub the object function in a special case. The same approach work in v15.0.2
The example code that shows the problem based on attempt to stub ChaplinJS utils object.
To Reproduce Open code sandbox based on v15.0.4 and see console log https://codesandbox.io/p/sandbox/sinon-module-stub-broken-15-0-4-9e1f4u
Console:
Expected behavior Open code sandbox based on v15.0.2 and see console log https://codesandbox.io/p/sandbox/sinon-module-stub-working-15-0-2-tipumo
Console: