Closed Xavier-Redondo closed 11 months ago
I think you might have stumbled upon a bug. Spying/stubbing propertie/synthetic fields is relatively rare, so maybe not many actually tried all that hard, and I am guessing the tests simply test that creation and restore works, but haven't touched the same function twice.
Hi, the example code is not actually reproducible in any sense. The return values do not match what your function created, using spy instead of stub, etc.
In any case, I tried manually reproducing it in this RunKit book: https://runkit.com/fatso83/649df02251b50f0008d1e3a6
Object.defineProperty
line must be wrong, because it lacks the configure: true
bit, which is what allows Sinon to mutate the field. If you do not provide that, it will fail early.So I found a bug, but not the one you seem to indicate. Can you please provide a minimally reproducible example that shows the issue? Have a look at my code in the RunKit for inspiration.
Made #2534. Closing due to lack of response
Describe the bug
I want to reset an spy on a function that typescript exports as a getter function. Instead of having the expected behaviour i get: "Attempted to wrap undefined property executeInsert as function"
I would like to know which is the canonical/official way to reset/restore a getter function from a library.
As a workaround i am using import-fresh to re-import from a clean cache every time the library myLibrary and then the tests works, but i would expect that this would not be required .
To Reproduce
3.In the test i do the following (what the test does it is not that important, since the test works fine when executed individually):
This does not happen with other stuff that i have mocked/stubbed, only with the spies against my getters (i have not put all the code to make the issue as short as possible).
Expected behavior
I would expect the spy restored/reset and the second test running successfully.
Screenshots If applicable, add screenshots to help explain your problem.
Context (please complete the following information):
Additional context
The tests that i have put as example are totally fine and each test works perfectly fine if run by itself. Is at the moment when the spy should be reset that the second test fails.
it is not relevant whether is best to use directly sinon or a sandbox, i have tested both and none work.
the same with reset or restore, it seems that for spies reset must be used but in any case if the issue is that i am not using the right method any hint would be appreciated as well.