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