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

Created on 3 May 2017  ·  12Comments  ·  Source: sinonjs/sinon

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?

Easy Documentation

Most helpful comment

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();

All 12 comments

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

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

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

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.

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();

@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

@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

@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.

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

@neetocode
You should stub _AnyModel.findById_ method like this:

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

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

@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.

Was this page helpful?
0 / 5 - 0 ratings