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

suppress_ajax_errors_during_navigation_spec.js « utils « lib « frontend « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b9c1d65738d90fbf5c3146c892a94a8ad85ee319 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import waitForPromises from 'helpers/wait_for_promises';
import suppressAjaxErrorsDuringNavigation from '~/lib/utils/suppress_ajax_errors_during_navigation';

describe('suppressAjaxErrorsDuringNavigation', () => {
  const OTHER_ERR_CODE = 'foo';
  const NAV_ERR_CODE = 'ECONNABORTED';

  it.each`
    isFeatureFlagEnabled | isUserNavigating | code
    ${false}             | ${false}         | ${OTHER_ERR_CODE}
    ${false}             | ${false}         | ${NAV_ERR_CODE}
    ${false}             | ${true}          | ${OTHER_ERR_CODE}
    ${false}             | ${true}          | ${NAV_ERR_CODE}
    ${true}              | ${false}         | ${OTHER_ERR_CODE}
    ${true}              | ${false}         | ${NAV_ERR_CODE}
    ${true}              | ${true}          | ${OTHER_ERR_CODE}
  `('should return a rejected Promise', ({ isFeatureFlagEnabled, isUserNavigating, code }) => {
    const err = { code };
    const actual = suppressAjaxErrorsDuringNavigation(err, isUserNavigating, isFeatureFlagEnabled);

    return expect(actual).rejects.toBe(err);
  });

  it('should return a Promise that never resolves', () => {
    const err = { code: NAV_ERR_CODE };
    const actual = suppressAjaxErrorsDuringNavigation(err, true, true);

    const thenCallback = jest.fn();
    const catchCallback = jest.fn();
    actual.then(thenCallback).catch(catchCallback);

    return waitForPromises().then(() => {
      expect(thenCallback).not.toHaveBeenCalled();
      expect(catchCallback).not.toHaveBeenCalled();
    });
  });
});