Skip to content

Conversation

@sdotson
Copy link
Contributor

@sdotson sdotson commented Oct 21, 2025

Purpose (TL;DR) - mandatory

Fix issue #2533 by improving the error message for immutable property descriptors to be more helpful and include a link to new FAQ documentation that explains the problem and provides solutions.

Background (Problem in detail) - optional

This PR addresses GitHub issue #2533 (#2533) where users encounter an unhelpful error message when trying to stub properties with immutable descriptors: "Descriptor for property X is non-configurable and non-writable".

This error commonly occurs when:

  • ES modules are transpiled to CommonJS (TypeScript, Babel, SWC)
  • Objects have been frozen or sealed
  • Working with native browser/Node.js APIs
  • Using third-party libraries with immutable exports

The original error message provided no guidance on what causes this issue or how to resolve it, leading to user frustration and support requests.

Solution - optional

This solution works by:

  1. Improving the error message in lib/sinon/stub.js to explain that Sinon cannot stub immutable properties and includes a direct link to documentation
  2. Creating comprehensive FAQ documentation at docs/faq.md that explains what causes immutable descriptors and provides practical solutions like dependency injection and module-level stubbing
  3. Updating tests and comments to reflect the new error message format

The new error message is more actionable and guides users to solutions rather than leaving them confused about what went wrong.

How to verify - mandatory

  1. Check out this branch
  2. npm install
  3. npm test - verify all tests pass with the updated error message expectations
  4. Create a test case with an immutable property descriptor and verify the new error message appears with the FAQ link
  5. Check that the new FAQ page exists at docs/faq.md and contains helpful content about property descriptor errors

Checklist for author

  • npm run lint passes
  • References to standard library functions are cached.

Copy link
Contributor

@fatso83 fatso83 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super! An improvement on the current situation, no doubt

@fatso83 fatso83 merged commit 2605504 into sinonjs:main Oct 22, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants