Commit e37aef1e authored by Vitaly Slobodin's avatar Vitaly Slobodin

Remove wait_using_real_timer helper

This helper does not make any sense because
- we use fake timers in unit tests and turning on real timers leads to
side effects.
- jest provides a set of convenient APIs that should be used instead.
parent 5e2a6116
/* useful for timing promises when jest fakeTimers are not reliable enough */
export default (timeout) =>
new Promise((resolve) => {
jest.useRealTimers();
setTimeout(resolve, timeout);
jest.useFakeTimers();
});
...@@ -5,7 +5,6 @@ import Vue from 'vue'; ...@@ -5,7 +5,6 @@ import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import '~/behaviors/markdown/render_gfm'; import '~/behaviors/markdown/render_gfm';
import waitForPromises from 'helpers/wait_for_promises'; import waitForPromises from 'helpers/wait_for_promises';
import waitUsingRealTimer from 'helpers/wait_using_real_timer';
import { exampleConfigs, exampleFiles } from 'jest/ide/lib/editorconfig/mock_data'; import { exampleConfigs, exampleFiles } from 'jest/ide/lib/editorconfig/mock_data';
import { EDITOR_CODE_INSTANCE_FN, EDITOR_DIFF_INSTANCE_FN } from '~/editor/constants'; import { EDITOR_CODE_INSTANCE_FN, EDITOR_DIFF_INSTANCE_FN } from '~/editor/constants';
import { EditorMarkdownExtension } from '~/editor/extensions/source_editor_markdown_ext'; import { EditorMarkdownExtension } from '~/editor/extensions/source_editor_markdown_ext';
...@@ -540,7 +539,6 @@ describe('RepoEditor', () => { ...@@ -540,7 +539,6 @@ describe('RepoEditor', () => {
}, },
}); });
await vm.$nextTick(); await vm.$nextTick();
await vm.$nextTick();
expect(vm.initEditor).toHaveBeenCalled(); expect(vm.initEditor).toHaveBeenCalled();
}); });
...@@ -567,8 +565,8 @@ describe('RepoEditor', () => { ...@@ -567,8 +565,8 @@ describe('RepoEditor', () => {
// switching from edit to diff mode usually triggers editor initialization // switching from edit to diff mode usually triggers editor initialization
vm.$store.state.viewer = viewerTypes.diff; vm.$store.state.viewer = viewerTypes.diff;
// we delay returning the file to make sure editor doesn't initialize before we fetch file content jest.runOnlyPendingTimers();
await waitUsingRealTimer(30);
return 'rawFileData123\n'; return 'rawFileData123\n';
}); });
...@@ -598,8 +596,9 @@ describe('RepoEditor', () => { ...@@ -598,8 +596,9 @@ describe('RepoEditor', () => {
return aContent; return aContent;
}) })
.mockImplementationOnce(async () => { .mockImplementationOnce(async () => {
// we delay returning fileB content to make sure the editor doesn't initialize prematurely // we delay returning fileB content
await waitUsingRealTimer(30); // to make sure the editor doesn't initialize prematurely
jest.advanceTimersByTime(30);
return bContent; return bContent;
}); });
......
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