Commit 114fcce9 authored by Paul Slaughter's avatar Paul Slaughter

Merge branch 'winh-jest-clear-mocks' into 'master'

Clear Jest mocks globally

Closes #118500

See merge request gitlab-org/gitlab!21860
parents 05926f42 cb0bf392
...@@ -62,7 +62,6 @@ describe('AlertWidget', () => { ...@@ -62,7 +62,6 @@ describe('AlertWidget', () => {
const findCurrentSettings = () => wrapper.find('.alert-current-setting'); const findCurrentSettings = () => wrapper.find('.alert-current-setting');
afterEach(() => { afterEach(() => {
jest.clearAllMocks();
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
}); });
......
...@@ -22,7 +22,6 @@ describe('BlockingMrInput', () => { ...@@ -22,7 +22,6 @@ describe('BlockingMrInput', () => {
afterEach(() => { afterEach(() => {
document.querySelector('#test').remove(); document.querySelector('#test').remove();
jest.clearAllMocks();
}); });
it('adds hidden references block when hidden count is greater than 0', () => { it('adds hidden references block when hidden count is greater than 0', () => {
......
...@@ -66,7 +66,6 @@ describe('Project Manager component', () => { ...@@ -66,7 +66,6 @@ describe('Project Manager component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
jest.clearAllMocks();
}); });
describe('given the default state', () => { describe('given the default state', () => {
......
...@@ -29,7 +29,6 @@ describe('projectSelector actions', () => { ...@@ -29,7 +29,6 @@ describe('projectSelector actions', () => {
}); });
afterEach(() => { afterEach(() => {
jest.clearAllMocks();
mockAxios.restore(); mockAxios.restore();
}); });
......
...@@ -24,10 +24,6 @@ describe('Vulnerable Projects actions', () => { ...@@ -24,10 +24,6 @@ describe('Vulnerable Projects actions', () => {
state = createState(); state = createState();
}); });
afterEach(() => {
jest.clearAllMocks();
});
describe('fetchProjects', () => { describe('fetchProjects', () => {
beforeEach(() => { beforeEach(() => {
mockAxios = new MockAdapter(axios); mockAxios = new MockAdapter(axios);
......
...@@ -54,8 +54,6 @@ describe('AccordionItem component', () => { ...@@ -54,8 +54,6 @@ describe('AccordionItem component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
jest.clearAllMocks();
}); });
describe('rendering options', () => { describe('rendering options', () => {
......
...@@ -22,8 +22,6 @@ describe('Accordion component', () => { ...@@ -22,8 +22,6 @@ describe('Accordion component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
jest.clearAllMocks();
}); });
it('contains a default slot', () => { it('contains a default slot', () => {
......
...@@ -11,7 +11,6 @@ describe('DismissalCommentModalFooter', () => { ...@@ -11,7 +11,6 @@ describe('DismissalCommentModalFooter', () => {
afterEach(() => { afterEach(() => {
document.body.dataset.page = origPage; document.body.dataset.page = origPage;
jest.clearAllMocks();
wrapper.destroy(); wrapper.destroy();
}); });
......
...@@ -55,6 +55,7 @@ if (IS_EE) { ...@@ -55,6 +55,7 @@ if (IS_EE) {
// eslint-disable-next-line import/no-commonjs // eslint-disable-next-line import/no-commonjs
module.exports = { module.exports = {
clearMocks: true,
testMatch, testMatch,
moduleFileExtensions: ['js', 'json', 'vue'], moduleFileExtensions: ['js', 'json', 'vue'],
moduleNameMapper, moduleNameMapper,
......
...@@ -41,7 +41,6 @@ describe('boardsStore', () => { ...@@ -41,7 +41,6 @@ describe('boardsStore', () => {
afterEach(() => { afterEach(() => {
axiosMock.restore(); axiosMock.restore();
jest.clearAllMocks();
}); });
const setupDefaultResponses = () => { const setupDefaultResponses = () => {
......
...@@ -46,7 +46,6 @@ describe('Clusters', () => { ...@@ -46,7 +46,6 @@ describe('Clusters', () => {
afterEach(() => { afterEach(() => {
cluster.destroy(); cluster.destroy();
mock.restore(); mock.restore();
jest.clearAllMocks();
}); });
describe('class constructor', () => { describe('class constructor', () => {
......
...@@ -44,7 +44,6 @@ describe('Commit pipeline status component', () => { ...@@ -44,7 +44,6 @@ describe('Commit pipeline status component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
wrapper = null; wrapper = null;
jest.clearAllMocks();
}); });
describe('Visibility management', () => { describe('Visibility management', () => {
......
...@@ -272,14 +272,11 @@ describe('EKS Cluster Store Actions', () => { ...@@ -272,14 +272,11 @@ describe('EKS Cluster Store Actions', () => {
payload = { name: ['Create cluster failed'] }; payload = { name: ['Create cluster failed'] };
}); });
it('commits createClusterError mutation', () => { it('commits createClusterError mutation and displays flash message', () =>
testAction(actions.createClusterError, payload, state, [ testAction(actions.createClusterError, payload, state, [
{ type: CREATE_CLUSTER_ERROR, payload }, { type: CREATE_CLUSTER_ERROR, payload },
]); ]).then(() => {
});
it('creates a flash that displays the create cluster error', () => {
expect(createFlash).toHaveBeenCalledWith(payload.name[0]); expect(createFlash).toHaveBeenCalledWith(payload.name[0]);
}); }));
}); });
}); });
...@@ -68,10 +68,6 @@ describe('IDE clientside preview', () => { ...@@ -68,10 +68,6 @@ describe('IDE clientside preview', () => {
jest.useRealTimers(); jest.useRealTimers();
}); });
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
......
...@@ -111,8 +111,6 @@ describe('IDE pipelines actions', () => { ...@@ -111,8 +111,6 @@ describe('IDE pipelines actions', () => {
}); });
describe('fetchLatestPipeline', () => { describe('fetchLatestPipeline', () => {
beforeEach(() => {});
afterEach(() => { afterEach(() => {
stopPipelinePolling(); stopPipelinePolling();
clearEtagPoll(); clearEtagPoll();
......
...@@ -72,7 +72,6 @@ describe('Issuables list component', () => { ...@@ -72,7 +72,6 @@ describe('Issuables list component', () => {
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
mockAxios.restore(); mockAxios.restore();
jest.clearAllMocks();
window.location = oldLocation; window.location = oldLocation;
}); });
......
import * as textUtils from '~/lib/utils/text_utility';
jest.mock('~/lib/utils/text_utility');
describe('does restore mocks config work?', () => {
describe('shared spy', () => {
const spy = jest.fn();
beforeEach(() => {
spy();
});
it('is only called once', () => {
expect(spy).toHaveBeenCalledTimes(1);
});
it('is only called once B', () => {
expect(spy).toHaveBeenCalledTimes(1);
});
it('is only called once C', () => {
expect(spy).toHaveBeenCalledTimes(1);
});
});
describe('module mock', () => {
beforeEach(() => {
textUtils.humanize('');
});
it('is only called once', () => {
expect(textUtils.humanize).toHaveBeenCalledTimes(1);
});
it('is only called once B', () => {
expect(textUtils.humanize).toHaveBeenCalledTimes(1);
});
it('is only called once C', () => {
expect(textUtils.humanize).toHaveBeenCalledTimes(1);
});
});
});
...@@ -50,7 +50,6 @@ describe('issue_comment_form component', () => { ...@@ -50,7 +50,6 @@ describe('issue_comment_form component', () => {
afterEach(() => { afterEach(() => {
axiosMock.restore(); axiosMock.restore();
wrapper.destroy(); wrapper.destroy();
jest.clearAllMocks();
}); });
describe('user is logged in', () => { describe('user is logged in', () => {
......
...@@ -83,10 +83,6 @@ describe('Users admin page Modal Manager', () => { ...@@ -83,10 +83,6 @@ describe('Users admin page Modal Manager', () => {
jest.spyOn(document, 'removeEventListener'); jest.spyOn(document, 'removeEventListener');
}); });
afterEach(() => {
jest.clearAllMocks();
});
afterAll(() => { afterAll(() => {
jest.restoreAllMocks(); jest.restoreAllMocks();
}); });
......
...@@ -52,7 +52,6 @@ describe('Registry List', () => { ...@@ -52,7 +52,6 @@ describe('Registry List', () => {
}); });
afterEach(() => { afterEach(() => {
jest.clearAllMocks();
Vue.config.silent = false; Vue.config.silent = false;
wrapper.destroy(); wrapper.destroy();
}); });
......
...@@ -35,7 +35,6 @@ function factory(propsData = {}) { ...@@ -35,7 +35,6 @@ function factory(propsData = {}) {
describe('Repository table row component', () => { describe('Repository table row component', () => {
afterEach(() => { afterEach(() => {
vm.destroy(); vm.destroy();
jest.clearAllMocks();
}); });
it('renders table row', () => { it('renders table row', () => {
......
...@@ -54,8 +54,7 @@ describe('SentryConfig', () => { ...@@ -54,8 +54,7 @@ describe('SentryConfig', () => {
}); });
it('should not call setUser if there is no current user ID', () => { it('should not call setUser if there is no current user ID', () => {
jest.clearAllMocks(); SentryConfig.setUser.mockClear();
options.currentUserId = undefined; options.currentUserId = undefined;
SentryConfig.init(options); SentryConfig.init(options);
...@@ -167,8 +166,6 @@ describe('SentryConfig', () => { ...@@ -167,8 +166,6 @@ describe('SentryConfig', () => {
describe('if no err is provided', () => { describe('if no err is provided', () => {
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks();
SentryConfig.handleSentryErrors(event, req, config); SentryConfig.handleSentryErrors(event, req, config);
}); });
...@@ -191,8 +188,6 @@ describe('SentryConfig', () => { ...@@ -191,8 +188,6 @@ describe('SentryConfig', () => {
beforeEach(() => { beforeEach(() => {
req.responseText = undefined; req.responseText = undefined;
jest.clearAllMocks();
SentryConfig.handleSentryErrors(event, req, config, err); SentryConfig.handleSentryErrors(event, req, config, err);
}); });
......
...@@ -42,7 +42,6 @@ describe('Confidential Issue Sidebar Block', () => { ...@@ -42,7 +42,6 @@ describe('Confidential Issue Sidebar Block', () => {
}; };
beforeEach(() => { beforeEach(() => {
jest.clearAllMocks();
jest.spyOn(window.location, 'reload').mockImplementation(); jest.spyOn(window.location, 'reload').mockImplementation();
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment