-
-
Notifications
You must be signed in to change notification settings - Fork 768
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stub readonly property throw "Cannot stub non-existent property" #2266
Comments
However, assigning value beforehand to the property, then the stub will work. But I really don't want to invoke the constructor as it's prettty complicated.
output: test |
Currently working around with directly assigning to the stub object.
output: test |
We have made conscious decision to not allow stubbing non-existent properties, as that would make for some very confusing scenarios. The submitted code doesn't look like JavaScript to me, I don't know how to run it. Please create a new issue and fill in the template to save everyone some time. |
What are the confusing scenarios? |
@gukoff You can end up spending a lot of time barking up the wrong tree when you stub something that is never supposed to exist. It could be you stubbed the wrong thing, the wrong way or misspelled the property. Better safe than sorry. That is why we would much rather have an explicit call that tells your intent is to define a property that does not currently exist. The API we have talked about looks like The scenario above is about an object mutating itself. The changes are not persistent on any prototype and you do not need to clean it up afterwards. If you choose to construct an object without invoking its constructor, there's no big reason to not do the assignment directly, as he did, as you are already responsible for doing the construction yourself. |
Describe the bug
To Reproduce
Expected behavior
stub properly.
There is an old issue mentioning the same issue but is closed with a comment that is not quite helpful for me. #829
The text was updated successfully, but these errors were encountered: