How to use the restore function from sinon

Find comprehensive JavaScript sinon.restore code examples handpicked from public code repositorys.

16
17
18
19
20
21
22
23
24
25
    sandbox.stub(myAPI, 'hello');
});

afterEach(function () {
    // completely restore all fakes created through the sandbox
    sandbox.restore();
});

it('should be called once', function () {
    myAPI.hello();
fork icon810
star icon1
watch icon3

138
139
140
141
142
143
144
145
146
147
```
A unit test should not actually trigger a function's network activity. To test `getTodos()` without triggering its  network activity, use the `sinon.replace()` method to replace the `jQuery.ajax` method in your test. Restore the `jQuery.ajax` method after your test by calling `sinon.restore()` in your test runner's `after()` function.

```javascript
after(function () {
    sinon.restore();
});

it('makes a GET request for todo items', function () {
    sinon.replace(jQuery, 'ajax', sinon.fake());
fork icon810
star icon0
watch icon2

+ 3 other calls in file

245
246
247
248
249
250
251
252
253
254
  });
});

context('when using azure', () => {
  afterEach(() => tokenCache.resetCache());
  afterEach(() => sinon.restore());
  context('credential caching', () => {
    const cache = tokenCache;

    beforeEach(() => {
fork icon73
star icon67
watch icon30

+ 2 other calls in file

69
70
71
72
73
74
75
76
77
78
79
80
    },
  }
}


tap.afterEach(() => {
  sinon.restore()
})


const DEFAULT_ACTION_DATA = {
  packageVersion: TEST_VERSION,
fork icon7
star icon15
watch icon62

100
101
102
103
104
105
106
107
108
109
110
111
  }
}


experiment('lib/mappers/charge-module', () => {
  afterEach(async () => {
    sandbox.restore()
  })


  experiment('.mapInvoiceAccountToChargeModuleCustomer with a valid lastInvoiceAccountAddress', () => {
    let result
fork icon2
star icon4
watch icon8

9
10
11
12
13
14
15
16
17
18
19
20
21
22


const { expect } = chai




describe('Testa a rota /register', () => {
    afterEach(() => { sinon.restore() });


    it('Verificando se um usuário é registrado com sucesso', async () => {
        sinon.stub(User, 'create').resolves(mockRegister)
        sinon.stub(jwt, 'sign').onFirstCall().returns(mockToken);
fork icon0
star icon1
watch icon1

8
9
10
11
12
13
14
15
16
17
describe ('Testes da rota register, camada service', () => {
    describe('Teste se é realizado o cadastro com sucesso', () => {
        beforeEach(async () => {
            sinon.stub(Model, 'create').resolves(clienteResponse);
        });
        afterEach(async () => sinon.restore());
        it('Deve ser feito cadastro com sucesso e retornar um objeto de usuário com as chaves de registro e token', async () => {
            const user = await postUser(clienteRegister);
            expect(user).to.have.keys(clienteResponse);
        });
fork icon0
star icon0
watch icon1

+ 2 other calls in file