Commit cb404e18 authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch '344247-replace-setimmediate-in-tests-5' into 'master'

Remove setImmediate usage in specs

See merge request gitlab-org/gitlab!80371
parents 7caba595 bcff2d94
......@@ -583,33 +583,25 @@ describe('ErrorDetails', () => {
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
it('should track IGNORE status update', () => {
it('should track IGNORE status update', async () => {
Tracking.event.mockClear();
findUpdateIgnoreStatusButton().vm.$emit('click');
setImmediate(() => {
await findUpdateIgnoreStatusButton().trigger('click');
const { category, action } = trackErrorStatusUpdateOptions('ignored');
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
});
it('should track RESOLVE status update', () => {
it('should track RESOLVE status update', async () => {
Tracking.event.mockClear();
findUpdateResolveStatusButton().vm.$emit('click');
setImmediate(() => {
await findUpdateResolveStatusButton().trigger('click');
const { category, action } = trackErrorStatusUpdateOptions('resolved');
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
});
it('should track external Sentry link views', () => {
it('should track external Sentry link views', async () => {
Tracking.event.mockClear();
findExternalUrl().trigger('click');
setImmediate(() => {
const { category, action, label, property } = trackClickErrorLinkToSentryOptions(
externalUrl,
);
await findExternalUrl().trigger('click');
const { category, action, label, property } = trackClickErrorLinkToSentryOptions(externalUrl);
expect(Tracking.event).toHaveBeenCalledWith(category, action, { label, property });
});
});
});
});
......@@ -447,7 +447,7 @@ describe('ErrorTrackingList', () => {
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
it('should track status updates', () => {
it('should track status updates', async () => {
Tracking.event.mockClear();
const status = 'ignored';
findErrorActions().vm.$emit('update-issue-status', {
......@@ -455,10 +455,10 @@ describe('ErrorTrackingList', () => {
status,
});
setImmediate(() => {
await nextTick();
const { category, action } = trackErrorStatusUpdateOptions(status);
expect(Tracking.event).toHaveBeenCalledWith(category, action);
});
});
});
});
......@@ -71,12 +71,12 @@ describe('Feature flags', () => {
describe('when limit exceeded', () => {
const provideData = { ...mockData, featureFlagsLimitExceeded: true };
beforeEach((done) => {
beforeEach(() => {
mock
.onGet(`${TEST_HOST}/endpoint.json`, { params: { page: '1' } })
.reply(200, getRequestData, {});
factory(provideData);
setImmediate(done);
return waitForPromises();
});
it('makes the new feature flag button do nothing if clicked', () => {
......@@ -116,12 +116,12 @@ describe('Feature flags', () => {
userListPath: null,
};
beforeEach((done) => {
beforeEach(() => {
mock
.onGet(`${TEST_HOST}/endpoint.json`, { params: { page: '1' } })
.reply(200, getRequestData, {});
factory(provideData);
setImmediate(done);
return waitForPromises();
});
it('does not render configure button', () => {
......@@ -202,7 +202,7 @@ describe('Feature flags', () => {
});
describe('with paginated feature flags', () => {
beforeEach((done) => {
beforeEach(() => {
mock.onGet(mockState.endpoint, { params: { page: '1' } }).replyOnce(200, getRequestData, {
'x-next-page': '2',
'x-page': '1',
......@@ -214,7 +214,7 @@ describe('Feature flags', () => {
factory();
jest.spyOn(store, 'dispatch');
setImmediate(done);
return waitForPromises();
});
it('should render a table with feature flags', () => {
......@@ -270,11 +270,11 @@ describe('Feature flags', () => {
});
describe('unsuccessful request', () => {
beforeEach((done) => {
beforeEach(() => {
mock.onGet(mockState.endpoint, { params: { page: '1' } }).replyOnce(500, {});
factory();
setImmediate(done);
return waitForPromises();
});
it('should render error state', () => {
......@@ -300,12 +300,12 @@ describe('Feature flags', () => {
});
describe('rotate instance id', () => {
beforeEach((done) => {
beforeEach(() => {
mock
.onGet(`${TEST_HOST}/endpoint.json`, { params: { page: '1' } })
.reply(200, getRequestData, {});
factory();
setImmediate(done);
return waitForPromises();
});
it('should fire the rotate action when a `token` event is received', () => {
......
import axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import FilteredSearchSpecHelper from 'helpers/filtered_search_spec_helper';
import waitForPromises from 'helpers/wait_for_promises';
import FilteredSearchVisualTokens from '~/filtered_search/filtered_search_visual_tokens';
describe('Filtered Search Visual Tokens', () => {
......@@ -715,18 +716,16 @@ describe('Filtered Search Visual Tokens', () => {
`);
});
it('renders a author token value element', () => {
it('renders a author token value element', async () => {
const { tokenNameElement, tokenValueElement } = findElements(authorToken);
const tokenName = tokenNameElement.textContent;
const tokenValue = 'new value';
subject.renderVisualTokenValue(authorToken, tokenName, tokenValue);
jest.runOnlyPendingTimers();
await waitForPromises();
setImmediate(() => {
expect(tokenValueElement.textContent).toBe(tokenValue);
});
});
});
});
......@@ -517,16 +517,12 @@ describe('Flash', () => {
`;
});
it('removes global flash on click', (done) => {
it('removes global flash on click', () => {
addDismissFlashClickListener(el, false);
el.querySelector('.js-close-icon').click();
setImmediate(() => {
expect(document.querySelector('.flash')).toBeNull();
done();
});
});
});
......
......@@ -8,7 +8,7 @@ describe('GLForm', () => {
const testContext = {};
describe('when instantiated', () => {
beforeEach((done) => {
beforeEach(() => {
window.gl = window.gl || {};
testContext.form = $('<form class="gfm-form"><textarea class="js-gfm-input"></form>');
......@@ -18,22 +18,11 @@ describe('GLForm', () => {
jest.spyOn($.prototype, 'css').mockImplementation(() => {});
testContext.glForm = new GLForm(testContext.form, false);
setImmediate(() => {
$.prototype.off.mockClear();
$.prototype.on.mockClear();
$.prototype.css.mockClear();
done();
});
});
describe('setupAutosize', () => {
beforeEach((done) => {
beforeEach(() => {
testContext.glForm.setupAutosize();
setImmediate(() => {
done();
});
});
it('should register an autosize event handler on the textarea', () => {
......
import Vue, { nextTick } from 'vue';
import { trimText } from 'helpers/text_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { createComponentWithStore } from 'helpers/vue_mount_component_helper';
import listItem from '~/ide/components/commit_sidebar/list_item.vue';
import { createRouter } from '~/ide/ide_router';
......@@ -55,32 +56,28 @@ describe('Multi-file editor commit sidebar list item', () => {
expect(findPathText()).toEqual(f.name);
});
it('opens a closed file in the editor when clicking the file path', (done) => {
it('opens a closed file in the editor when clicking the file path', async () => {
jest.spyOn(vm, 'openPendingTab');
jest.spyOn(router, 'push').mockImplementation(() => {});
findPathEl.click();
setImmediate(() => {
await nextTick();
expect(vm.openPendingTab).toHaveBeenCalled();
expect(router.push).toHaveBeenCalled();
done();
});
});
it('calls updateViewer with diff when clicking file', (done) => {
it('calls updateViewer with diff when clicking file', async () => {
jest.spyOn(vm, 'openFileInEditor');
jest.spyOn(vm, 'updateViewer');
jest.spyOn(router, 'push').mockImplementation(() => {});
findPathEl.click();
setImmediate(() => {
expect(vm.updateViewer).toHaveBeenCalledWith('diff');
await waitForPromises();
done();
});
expect(vm.updateViewer).toHaveBeenCalledWith('diff');
});
describe('computed', () => {
......
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