sinonjs / sinon

Test spies, stubs and mocks for JavaScript.

Home Page:https://sinonjs.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improve error message for immutable descriptors to include link to article

fatso83 opened this issue · comments

Is your feature request related to a problem? Please describe.
See #2528 (comment). Currently it seems people get stuck when seeing the error message "Descriptor for property toBeMocked is non-configurable and non-writable" and think this is some sort of error in Sinon.

Describe the solution you'd like
I was thinking that it might be useful to have error messages point directly to relevant docs that could give the user some context and possible hints at resolving the issue. So instead of "Descriptor for property toBeMocked is non-configurable and non-writable" change it to something like

The descriptor for the property toBeMocked is non-configurable and non-writable. Sinon cannot do anything about this, as it is essentially immutable. Read https://sinonjs.org/faqs#immutable-objectdescriptor for tips on what could cause this and how to possibly resolve it.

(The link is made up by the way). A fix should of course then include a new page in our docs that deals with that specific error. It could contain a short summary of possible reasons the descriptor is immutable (such as transpilation of ESM) and links to articles that show how to solve it.