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', () => {
const findCurrentSettings = () => wrapper.find('.alert-current-setting');
afterEach(() => {
jest.clearAllMocks();
wrapper.destroy();
wrapper = null;
});
......
......@@ -22,7 +22,6 @@ describe('BlockingMrInput', () => {
afterEach(() => {
document.querySelector('#test').remove();
jest.clearAllMocks();
});
it('adds hidden references block when hidden count is greater than 0', () => {
......
......@@ -66,7 +66,6 @@ describe('Project Manager component', () => {
afterEach(() => {
wrapper.destroy();
jest.clearAllMocks();
});
describe('given the default state', () => {
......
......@@ -29,7 +29,6 @@ describe('projectSelector actions', () => {
});
afterEach(() => {
jest.clearAllMocks();
mockAxios.restore();
});
......
......@@ -24,10 +24,6 @@ describe('Vulnerable Projects actions', () => {
state = createState();
});
afterEach(() => {
jest.clearAllMocks();
});
describe('fetchProjects', () => {
beforeEach(() => {
mockAxios = new MockAdapter(axios);
......
......@@ -54,8 +54,6 @@ describe('AccordionItem component', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
jest.clearAllMocks();
});
describe('rendering options', () => {
......
......@@ -22,8 +22,6 @@ describe('Accordion component', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
jest.clearAllMocks();
});
it('contains a default slot', () => {
......
......@@ -11,7 +11,6 @@ describe('DismissalCommentModalFooter', () => {
afterEach(() => {
document.body.dataset.page = origPage;
jest.clearAllMocks();
wrapper.destroy();
});
......
......@@ -55,6 +55,7 @@ if (IS_EE) {
// eslint-disable-next-line import/no-commonjs
module.exports = {
clearMocks: true,
testMatch,
moduleFileExtensions: ['js', 'json', 'vue'],
moduleNameMapper,
......
......@@ -41,7 +41,6 @@ describe('boardsStore', () => {
afterEach(() => {
axiosMock.restore();
jest.clearAllMocks();
});
const setupDefaultResponses = () => {
......
......@@ -46,7 +46,6 @@ describe('Clusters', () => {
afterEach(() => {
cluster.destroy();
mock.restore();
jest.clearAllMocks();
});
describe('class constructor', () => {
......
......@@ -44,7 +44,6 @@ describe('Commit pipeline status component', () => {
afterEach(() => {
wrapper.destroy();
wrapper = null;
jest.clearAllMocks();
});
describe('Visibility management', () => {
......
......@@ -272,14 +272,11 @@ describe('EKS Cluster Store Actions', () => {
payload = { name: ['Create cluster failed'] };
});
it('commits createClusterError mutation', () => {
it('commits createClusterError mutation and displays flash message', () =>
testAction(actions.createClusterError, payload, state, [
{ type: CREATE_CLUSTER_ERROR, payload },
]);
});
it('creates a flash that displays the create cluster error', () => {
expect(createFlash).toHaveBeenCalledWith(payload.name[0]);
});
]).then(() => {
expect(createFlash).toHaveBeenCalledWith(payload.name[0]);
}));
});
});
......@@ -68,10 +68,6 @@ describe('IDE clientside preview', () => {
jest.useRealTimers();
});
beforeEach(() => {
jest.clearAllMocks();
});
afterEach(() => {
wrapper.destroy();
});
......
......@@ -111,8 +111,6 @@ describe('IDE pipelines actions', () => {
});
describe('fetchLatestPipeline', () => {
beforeEach(() => {});
afterEach(() => {
stopPipelinePolling();
clearEtagPoll();
......
......@@ -72,7 +72,6 @@ describe('Issuables list component', () => {
afterEach(() => {
wrapper.destroy();
mockAxios.restore();
jest.clearAllMocks();
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', () => {
afterEach(() => {
axiosMock.restore();
wrapper.destroy();
jest.clearAllMocks();
});
describe('user is logged in', () => {
......
......@@ -83,10 +83,6 @@ describe('Users admin page Modal Manager', () => {
jest.spyOn(document, 'removeEventListener');
});
afterEach(() => {
jest.clearAllMocks();
});
afterAll(() => {
jest.restoreAllMocks();
});
......
......@@ -52,7 +52,6 @@ describe('Registry List', () => {
});
afterEach(() => {
jest.clearAllMocks();
Vue.config.silent = false;
wrapper.destroy();
});
......
......@@ -35,7 +35,6 @@ function factory(propsData = {}) {
describe('Repository table row component', () => {
afterEach(() => {
vm.destroy();
jest.clearAllMocks();
});
it('renders table row', () => {
......
......@@ -54,8 +54,7 @@ describe('SentryConfig', () => {
});
it('should not call setUser if there is no current user ID', () => {
jest.clearAllMocks();
SentryConfig.setUser.mockClear();
options.currentUserId = undefined;
SentryConfig.init(options);
......@@ -167,8 +166,6 @@ describe('SentryConfig', () => {
describe('if no err is provided', () => {
beforeEach(() => {
jest.clearAllMocks();
SentryConfig.handleSentryErrors(event, req, config);
});
......@@ -191,8 +188,6 @@ describe('SentryConfig', () => {
beforeEach(() => {
req.responseText = undefined;
jest.clearAllMocks();
SentryConfig.handleSentryErrors(event, req, config, err);
});
......
......@@ -42,7 +42,6 @@ describe('Confidential Issue Sidebar Block', () => {
};
beforeEach(() => {
jest.clearAllMocks();
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