summaryrefslogtreecommitdiff
path: root/spec/frontend/locale/index_spec.js
blob: 346ed5182f4134dd9fc56861f6301c2e93affca0 (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
import { createDateTimeFormat, languageCode } from '~/locale';

import { setLanguage } from 'helpers/locale_helper';

describe('locale', () => {
  afterEach(() => setLanguage(null));

  describe('languageCode', () => {
    it('parses the lang attribute', () => {
      setLanguage('ja');

      expect(languageCode()).toBe('ja');
    });

    it('falls back to English', () => {
      setLanguage(null);

      expect(languageCode()).toBe('en');
    });
  });

  describe('createDateTimeFormat', () => {
    beforeEach(() => setLanguage('en'));

    it('creates an instance of Intl.DateTimeFormat', () => {
      const dateFormat = createDateTimeFormat({ year: 'numeric', month: 'long', day: 'numeric' });

      expect(dateFormat.format(new Date(2015, 6, 3))).toBe('July 3, 2015');
    });
  });
});