2019-09-27 18:06:20 +00:00
|
|
|
import waitForPromises from 'helpers/wait_for_promises';
|
2019-12-10 09:07:51 +00:00
|
|
|
import suppressAjaxErrorsDuringNavigation from '~/lib/utils/suppress_ajax_errors_during_navigation';
|
2019-09-27 18:06:20 +00:00
|
|
|
|
|
|
|
describe('suppressAjaxErrorsDuringNavigation', () => {
|
|
|
|
const OTHER_ERR_CODE = 'foo';
|
|
|
|
const NAV_ERR_CODE = 'ECONNABORTED';
|
|
|
|
|
|
|
|
it.each`
|
2019-12-16 12:07:43 +00:00
|
|
|
isUserNavigating | code
|
|
|
|
${false} | ${OTHER_ERR_CODE}
|
|
|
|
${false} | ${NAV_ERR_CODE}
|
|
|
|
${true} | ${OTHER_ERR_CODE}
|
|
|
|
`('should return a rejected Promise', ({ isUserNavigating, code }) => {
|
2019-09-27 18:06:20 +00:00
|
|
|
const err = { code };
|
2019-12-16 12:07:43 +00:00
|
|
|
const actual = suppressAjaxErrorsDuringNavigation(err, isUserNavigating);
|
2019-09-27 18:06:20 +00:00
|
|
|
|
|
|
|
return expect(actual).rejects.toBe(err);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return a Promise that never resolves', () => {
|
|
|
|
const err = { code: NAV_ERR_CODE };
|
2019-12-16 12:07:43 +00:00
|
|
|
const actual = suppressAjaxErrorsDuringNavigation(err, true);
|
2019-09-27 18:06:20 +00:00
|
|
|
|
|
|
|
const thenCallback = jest.fn();
|
|
|
|
const catchCallback = jest.fn();
|
|
|
|
actual.then(thenCallback).catch(catchCallback);
|
|
|
|
|
|
|
|
return waitForPromises().then(() => {
|
|
|
|
expect(thenCallback).not.toHaveBeenCalled();
|
|
|
|
expect(catchCallback).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|