summaryrefslogtreecommitdiff
path: root/spec/frontend/helpers/fake_date_spec.js
blob: 8afc8225f9ba862fcaef312877da9115be33ee88 (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
import { createFakeDateClass, DEFAULT_ARGS, useRealDate } from './fake_date';

describe('spec/helpers/fake_date', () => {
  describe('createFakeDateClass', () => {
    let FakeDate;

    beforeAll(() => {
      useRealDate();
    });

    beforeEach(() => {
      FakeDate = createFakeDateClass(DEFAULT_ARGS);
    });

    it('should use default args', () => {
      expect(new FakeDate()).toEqual(new Date(...DEFAULT_ARGS));
      expect(FakeDate()).toEqual(Date(...DEFAULT_ARGS));
    });

    it('should have deterministic now()', () => {
      expect(FakeDate.now()).not.toBe(Date.now());
      expect(FakeDate.now()).toBe(new Date(...DEFAULT_ARGS).getTime());
    });

    it('should be instanceof Date', () => {
      expect(new FakeDate()).toBeInstanceOf(Date);
    });

    it('should be instanceof self', () => {
      expect(new FakeDate()).toBeInstanceOf(FakeDate);
    });
  });
});