Skip to content
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

sinon.restore is deprecated and will be removed from the public API in a future version of sinon. #1390

Closed
sweetim opened this issue May 3, 2017 · 12 comments

Comments

@sweetim
Copy link

sweetim commented May 3, 2017

I am getting the warning above, after upgrading from Sinon v1.7 to Sinon v2.2

but, i check the document sinon.restore is not deprecated, any idea?

@mantoni
Copy link
Member

mantoni commented May 3, 2017

Yes, it's missing in the docs. This is an internal utility function and was deprecated in Sinon v2.

@mantoni
Copy link
Member

mantoni commented May 3, 2017

Fixed. It should show up in the migration guides deprecation list shortly.

@sweetim
Copy link
Author

sweetim commented May 3, 2017

awesome! but how to migrate from using sinon.restore ?
Just dont use it?

@mantoni
Copy link
Member

mantoni commented May 3, 2017

You can call restore on stubs and sandbox instances. The global sandbox.restore was never meant to be used, but since it was there we had to introduce a deprecation warning before removing it entirely. It wasn't even documented in the legacy docs.

@sweetim
Copy link
Author

sweetim commented May 3, 2017

I created a sample migration code below, for anyone who has the same problem

// Previously
sinon.restore(stubObject);

// After for Typescript user
(stubObject as any).restore();

// After for Javascript user
stubObject.restore();

@kopax
Copy link

kopax commented Jun 9, 2017

@sweetim I had this :

  afterEach(() => {
    clock = sinon.restore();
  });

I replaced as in your migration example :

  beforeEach(() => {
    clock = sinon.useFakeTimers();
  });
  afterEach(() => {
    clock.restore();
  });

I have now this error :

    TypeError: Cannot read property 'restore' of undefined

@fatso83
Copy link
Contributor

fatso83 commented Jun 9, 2017

@kopax we are trying to keep the issue tracker for bugs in the code. this seems like a usage question, in which case you could try our mailing list, Gitter or stackoverflow. Your code example works with Sinon 2.3 and Node 7.4, so your code must be doing something else (for instance restoring the clock before hitting the afterEach). Just tried this:

> clock=sinon.useFakeTimers()
> Date.now()
0
> clock.restore()
> Date.now()
1496995253874

@kopax
Copy link

kopax commented Jun 9, 2017

@fatso83 I upgraded to sinon 2.3.2 and Node 7.10 and now it work. Thanks I will use the gitter in the futur.

@neetocode
Copy link

neetocode commented Aug 1, 2017

i have this code with error

AnyModel.findById = sinon.stub()

AnyModel.findById.resolves({})

AnyModel.findById.restore() // TypeError: _models.AnyModel.findById.restore is not a function

AnyModel is a model by mongoosejs

using sinon.restore() works, but give me message

AnyModel.findById = sinon.restore() 
// sinon.restore is deprecated and will be removed from the public API in a future version of sinon.

i using sinon 2.4.1

@davinci2015
Copy link

@neetocode
You should stub AnyModel.findById method like this:

const findByIdStub = sinon.stub(AnyModel, 'findById').resolves({})

@jackson-sandland
Copy link

This is still an issue. The warning indicates that use of .restore() is the better approach because of impending deprecation, but using .restore() results in .restore is not a function I'm using sinon 2.0.0

@fatso83
Copy link
Contributor

fatso83 commented Oct 6, 2017

@jackson-sandland, file an issue if there is something wrong in Sinon 4.x. It needs to include a snippet that shows what is wrong. Your "still a problem" for an issue that was about missing documentation for a deprecated method doesn't really say much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants