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

accessor_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: 63497d795ce3c5d5cb195680d1da57ddcc63f432 (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
import { useLocalStorageSpy } from 'helpers/local_storage_helper';
import AccessorUtilities from '~/lib/utils/accessor';

describe('AccessorUtilities', () => {
  useLocalStorageSpy();

  const testError = new Error('test error');

  describe('canUseLocalStorage', () => {
    it('should return `true` if access is safe', () => {
      expect(AccessorUtilities.canUseLocalStorage()).toBe(true);
    });

    it('should return `false` if access to .setItem isnt safe', () => {
      window.localStorage.setItem.mockImplementation(() => {
        throw testError;
      });

      expect(AccessorUtilities.canUseLocalStorage()).toBe(false);
    });

    it('should set a test item if access is safe', () => {
      AccessorUtilities.canUseLocalStorage();

      expect(window.localStorage.setItem).toHaveBeenCalledWith('canUseLocalStorage', 'true');
    });

    it('should remove the test item if access is safe', () => {
      AccessorUtilities.canUseLocalStorage();

      expect(window.localStorage.removeItem).toHaveBeenCalledWith('canUseLocalStorage');
    });
  });
});