Commit 755fc84b authored by lauraMon's avatar lauraMon

Fixes flaky spec by mocking debounce/throttle functions

* Removes all instances of mocked throttle from spec
* Removes all instances of mocked debounce from specs
* Adds global helper
parent d10ee385
...@@ -35,7 +35,6 @@ const MERGE_REQUEST_CLOSED = 'merge_request_closed'; ...@@ -35,7 +35,6 @@ const MERGE_REQUEST_CLOSED = 'merge_request_closed';
let store = null; let store = null;
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
jest.mock('lodash/debounce', () => jest.fn);
describe('CustomStageForm', () => { describe('CustomStageForm', () => {
function createComponent(props = {}, stubs = {}) { function createComponent(props = {}, stubs = {}) {
......
...@@ -20,8 +20,6 @@ const findFlashError = () => document.querySelector('.flash-container .flash-tex ...@@ -20,8 +20,6 @@ const findFlashError = () => document.querySelector('.flash-container .flash-tex
const mockGroupLabelsRequest = (status = 200) => const mockGroupLabelsRequest = (status = 200) =>
new MockAdapter(axios).onGet().reply(status, groupLabels); new MockAdapter(axios).onGet().reply(status, groupLabels);
jest.mock('lodash/debounce', () => jest.fn);
describe('Value Stream Analytics LabelsSelector', () => { describe('Value Stream Analytics LabelsSelector', () => {
let store = null; let store = null;
const localVue = createLocalVue(); const localVue = createLocalVue();
......
...@@ -32,7 +32,6 @@ const selectLabelAtIndex = (ctx, index) => { ...@@ -32,7 +32,6 @@ const selectLabelAtIndex = (ctx, index) => {
const mockGroupLabelsRequest = () => new MockAdapter(axios).onGet().reply(200, groupLabels); const mockGroupLabelsRequest = () => new MockAdapter(axios).onGet().reply(200, groupLabels);
jest.mock('lodash/debounce', () => jest.fn);
let store = null; let store = null;
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
......
...@@ -4,8 +4,6 @@ import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue'; ...@@ -4,8 +4,6 @@ import RuleInput from 'ee/approvals/components/mr_edit/rule_input.vue';
import MREditModule from 'ee/approvals/stores/modules/mr_edit'; import MREditModule from 'ee/approvals/stores/modules/mr_edit';
import { createStoreOptions } from 'ee/approvals/stores'; import { createStoreOptions } from 'ee/approvals/stores';
jest.mock('lodash/debounce', () => jest.fn(fn => fn));
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
......
...@@ -6,7 +6,6 @@ import { createStore } from '~/ide/stores'; ...@@ -6,7 +6,6 @@ import { createStore } from '~/ide/stores';
import eventHub from '~/ide/eventhub'; import eventHub from '~/ide/eventhub';
jest.mock('ee/ide/lib/mirror'); jest.mock('ee/ide/lib/mirror');
jest.mock('lodash/debounce', () => jest.fn);
const ACTION_START = 'terminalSync/start'; const ACTION_START = 'terminalSync/start';
const ACTION_STOP = 'terminalSync/stop'; const ACTION_STOP = 'terminalSync/stop';
......
...@@ -4,8 +4,6 @@ import { GlDeprecatedButton } from '@gitlab/ui'; ...@@ -4,8 +4,6 @@ import { GlDeprecatedButton } from '@gitlab/ui';
import DropdownSearchInput from 'ee/vue_shared/components/sidebar/epics_select/dropdown_search_input.vue'; import DropdownSearchInput from 'ee/vue_shared/components/sidebar/epics_select/dropdown_search_input.vue';
import Icon from '~/vue_shared/components/icon.vue'; import Icon from '~/vue_shared/components/icon.vue';
jest.mock('lodash/debounce', () => jest.fn(fn => fn));
const createComponent = () => const createComponent = () =>
shallowMount(DropdownSearchInput, { shallowMount(DropdownSearchInput, {
directives: { directives: {
......
// `lodash/debounce` has a non-trivial implementation which can lead to
// [flaky spec errors][1]. This mock simply makes `debounce` calls synchronous.
//
// In the future we could enhance this by injecting some test values in
// the function passed to it. See [this issue][2] for more information.
//
// [1]: https://gitlab.com/gitlab-org/gitlab/-/issues/212532
// [2]: https://gitlab.com/gitlab-org/gitlab/-/issues/213378
// Further reference: https://github.com/facebook/jest/issues/3465
export default fn => fn;
...@@ -9,8 +9,6 @@ import { branches } from '../../mock_data'; ...@@ -9,8 +9,6 @@ import { branches } from '../../mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
jest.mock('lodash/debounce', () => jest.fn);
describe('IDE branches search list', () => { describe('IDE branches search list', () => {
let wrapper; let wrapper;
const fetchBranchesMock = jest.fn(); const fetchBranchesMock = jest.fn();
......
...@@ -134,9 +134,7 @@ describe('IDE merge requests list', () => { ...@@ -134,9 +134,7 @@ describe('IDE merge requests list', () => {
createComponent(defaultStateWithMergeRequests); createComponent(defaultStateWithMergeRequests);
const input = findTokenedInput(); const input = findTokenedInput();
input.vm.$emit('input', 'something'); input.vm.$emit('input', 'something');
fetchMergeRequestsMock.mockClear();
jest.runAllTimers();
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(fetchMergeRequestsMock).toHaveBeenCalledWith( expect(fetchMergeRequestsMock).toHaveBeenCalledWith(
expect.any(Object), expect.any(Object),
......
...@@ -20,7 +20,7 @@ afterEach(() => ...@@ -20,7 +20,7 @@ afterEach(() =>
// give Promises a bit more time so they fail the right test // give Promises a bit more time so they fail the right test
new Promise(setImmediate).then(() => { new Promise(setImmediate).then(() => {
// wait for pending setTimeout()s // wait for pending setTimeout()s
jest.runAllTimers(); jest.runOnlyPendingTimers();
}), }),
); );
......
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