debian-mirror-gitlab/spec/frontend/lib/utils/is_navigating_away_spec.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

24 lines
689 B
JavaScript
Raw Normal View History

2021-11-18 22:05:49 +05:30
import { isNavigatingAway, setNavigatingForTestsOnly } from '~/lib/utils/is_navigating_away';
describe('isNavigatingAway', () => {
beforeEach(() => {
// Make sure each test starts with the same state
setNavigatingForTestsOnly(false);
});
2022-10-11 01:57:18 +05:30
it.each([false, true])('returns the navigation flag with value %s', (flag) => {
2021-11-18 22:05:49 +05:30
setNavigatingForTestsOnly(flag);
expect(isNavigatingAway()).toEqual(flag);
});
describe('when the browser starts navigating away', () => {
it('returns true', () => {
expect(isNavigatingAway()).toEqual(false);
window.dispatchEvent(new Event('beforeunload'));
expect(isNavigatingAway()).toEqual(true);
});
});
});