/
test.js
84 lines (72 loc) · 2.53 KB
/
test.js
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// @flow
/* eslint-env mocha */
import assert from 'power-assert'
import getWeekOfMonth from '.'
describe('getWeekOfMonth', function() {
it('returns the week of the month of the given date', function() {
var result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 15))
assert(result === 3)
})
describe('edge cases', function() {
context('when the given day is the first of a month', function() {
it('returns the week of the month of the given date', function() {
var result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 1))
assert(result === 1)
})
})
context('when the given day is the last of a month #1', function() {
it('returns the week of the month of the given date', function() {
var result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 30))
assert(result === 5)
})
})
context('when the given day is the last of a month #2', function() {
it('returns the week of the month of the given date', function() {
var result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 31))
assert(result === 5)
})
})
})
it('allows to specify which day is the first day of the week', function() {
var result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 1), {
weekStartsOn: 1
})
assert(result === 1)
})
it('allows to specify which day is the first day of the week in locale', function() {
var result = getWeekOfMonth(new Date(2017, 9 /* Oct */, 31), {
// $ExpectedMistake
locale: {
options: { weekStartsOn: 1 }
}
})
assert(result === 6)
})
it('`options.weekStartsOn` overwrites the first day of the week specified in locale', function() {
var result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 13), {
weekStartsOn: 1,
// $ExpectedMistake
locale: {
options: { weekStartsOn: 0 }
}
})
assert(result === 3)
})
it('accepts a timestamp', function() {
var result = getWeekOfMonth(new Date(2017, 10 /* Nov */, 1).getTime())
assert(result === 1)
})
it('returns NaN if the given date is invalid', function() {
var result = getWeekOfMonth(new Date(NaN))
assert(isNaN(result))
})
it('throws TypeError exception if passed less than 1 argument', function() {
assert.throws(getWeekOfMonth.bind(null), TypeError)
})
it('returns the week of the month of the given date, when the given date is sunday', function() {
var result = getWeekOfMonth(new Date(2019, 4 /* May */, 5), {
weekStartsOn: 1
})
assert(result === 1)
})
})