Throw error when trying to stub non-configurable or non-writable properties #2377
Labels
Awaiting Response
Difficulty: Easy
Feature Request
good first issue
Improvement
Property accessors
Property Getters/Setters
semver:major
changes will cause a new major version
Is your feature request related to a problem? Please describe.
Today we silently ignore stubbing issues, such as trying to use
sinon.stub(obj, 'prop')
, whenobj.prop
is a synthetic getter. From a user perspective, it is probably more user friendly to be explicitly told immediately that this Object.descriptor is non-configurable (perhaps even with a link to a Sinon doc page!) and cannot be stubbed, than the current behavior.This situation applies to a lot of different use cases, especially the ones involving transpilation using Webpack or TypeScript. For instance,lthough the #2319 PR talks about TypeScript and ECMAScript modules, this all basically boils down to:
Describe the solution you'd like
We should throw an error when encountering property descriptors that are not stubbable. While we have silently ignored these in the past, it is not like we don't already do this in our code base. We already throw errors if you try to stub a true ESM:
https://github.com/sinonjs/sinon/blob/master/test/es2015/module-support-assessment-test.es6#L53-L68
From MDN
So throw in these cases
isDataDescriptor
must return something based on this:Describe alternatives you've considered
Printing a one-time warning?
Additional context
#2319, #2238 and others
The text was updated successfully, but these errors were encountered: