Welcome to mirror list, hosted at ThFree Co, Russian Federation.

debounce.js « lodash « __mocks__ « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d4fe2ce54063c57ba58595c4cc0e5e3b0c308dd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// `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) => {
  const debouncedFn = jest.fn().mockImplementation(fn);
  debouncedFn.cancel = jest.fn();
  debouncedFn.flush = jest.fn().mockImplementation(() => {
    const errorMessage =
      "The .flush() method returned by lodash.debounce is not yet implemented/mocked by the mock in 'spec/frontend/__mocks__/lodash/debounce.js'.";

    throw new Error(errorMessage);
  });

  return debouncedFn;
};