summaryrefslogtreecommitdiff
path: root/date-fns/src/nextSaturday/test.ts
blob: 6799b462caa2f9f0abd381579a10e2cdd43610d2 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// @flow
/* eslint-env mocha */

import assert from 'power-assert'
import nextSaturday from '.'

describe('nextSaturday', () => {
  it('returns the following Saturday given various dates before the same', () => {
    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 23)),
      new Date(2020, 2 /* Mar */, 28)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 22)),
      new Date(2020, 2 /* Mar */, 28)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 21)),
      new Date(2020, 2 /* Mar */, 28)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 20)),
      new Date(2020, 2 /* Mar */, 21)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 19)),
      new Date(2020, 2 /* Mar */, 21)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 18)),
      new Date(2020, 2 /* Mar */, 21)
    )

    assert.deepStrictEqual(
      nextSaturday(new Date(2020, 2 /* Mar */, 17)),
      new Date(2020, 2 /* Mar */, 21)
    )
  })

  it('returns `Invalid Date` if the given date is invalid', () => {
    assert(nextSaturday(new Date(NaN)) instanceof Date)
  })
})