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();
810
1
3
GitHub: will3/sinon
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());
810
0
2
+ 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(() => {
73
67
30
+ 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,
7
15
62
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
2
4
8
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);
0
1
1
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); });
0
0
1
+ 2 other calls in file
sinon.stub is the most popular function in sinon (5777 examples)