jest: added restoreAllMocks

This commit is contained in:
firsttris
2017-09-20 19:45:34 +02:00
parent c30b86dfaa
commit 6c121d8c2f
2 changed files with 12 additions and 0 deletions

View File

@@ -60,6 +60,12 @@ declare namespace jest {
* Equivalent to calling .mockClear() on every mocked function.
*/
function resetAllMocks(): typeof jest;
/**
* available in Jest 20.1.0+
* Restores all mocks back to their original value. Equivalent to calling .mockRestore on every mocked function.
* Beware that jest.restoreAllMocks() only works when mock was created with jest.spyOn; other mocks will require you to manually restore them.
*/
function restoreAllMocks(): typeof jest;
/**
* Removes any pending timers from the timer system. If any timers have
* been scheduled, they will be cleared and will never have the opportunity

View File

@@ -17,6 +17,12 @@ describe('sum', () => {
});
});
describe('restoreAllMocks', () => {
afterEach(() => {
jest.restoreAllMocks();
});
});
describe('fetchCurrentUser', () => {
it('calls the callback when $.ajax requests are finished', () => {
const fetchCurrentUser = require('../fetchCurrentUser');