-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Restoring stub fails when it executed .value() #2226
Comments
Thank you for reporting this issue. Here's what I've learned so far in my investigation of this
|
The existing test at https://github.com/sinonjs/sinon/blob/master/test/stub-test.js#L3453-L3464 is a bit misleading, as it doesn't actually test restoring the stub. Adding a |
More experiments: This fails: var o = {};
Object.defineProperty(o, "test", { value: 1 });
Object.defineProperty(o, "test", { value: 2 }); This works: var o = {};
Object.defineProperty(o, "test", { writable: true, value: 1 });
Object.defineProperty(o, "test", { writable: true, value: 2 }); |
Here is clearly something wrong with property replacement / restoring: 'use strict';
const sinon = require('sinon');
const proto = {};
const obj = {};
Object.setPrototypeOf(obj, proto);
Object.defineProperty(proto, 'test', { writable: true, value: 1 });
sinon.replace(obj, 'test', 2);
console.log(Object.getOwnPropertyDescriptor(obj, 'test'));
sinon.restore();
console.log(Object.getOwnPropertyDescriptor(obj, 'test')); Prints
So after the |
This is basically the restoration of prototype props
Simple fix with a discussion of doing some (separate) deeper changes in #2237 |
The fix has been published to npm as |
Describe the bug
I made a stub with
mongoose.connection
'sreadyState
Property.And I executed
sinon.restore()
when test finished (withafterEach
)It throws TypeError when my stub restored.
To Reproduce
mongoose
,sinon
sinon.restore()
.Expected behavior
I tested this case with this code:
and It should prints
0
,1
,0
.but It throws error above before second
0
printedScreenshots
![image](https://user-images.githubusercontent.com/26434484/75134020-52ec2880-5720-11ea-8f9a-1baa1226e4fe.png)
Context (please complete the following information):
The text was updated successfully, but these errors were encountered: