summaryrefslogtreecommitdiff
path: root/date-fns/src/nextMonday/test.ts
blob: 281a31c6920583bc76913fc1583f48905743ccde (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 nextMonday from '.'

describe('nextMonday', function () {
  it('returns the following Monday given various dates before the same', function () {
    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 23)),
      new Date(2020, 2 /* Mar */, 30)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 22)),
      new Date(2020, 2 /* Mar */, 23)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 3 /* Apr */, 11)),
      new Date(2020, 3 /* Apr */, 13)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 20)),
      new Date(2020, 2 /* Mar */, 23)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 19)),
      new Date(2020, 2 /* Mar */, 23)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 18)),
      new Date(2020, 2 /* Mar */, 23)
    )

    assert.deepStrictEqual(
      nextMonday(new Date(2020, 2 /* Mar */, 17)),
      new Date(2020, 2 /* Mar */, 23)
    )
  })

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