summaryrefslogtreecommitdiff
path: root/date-fns/src/isLeapYear/test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'date-fns/src/isLeapYear/test.ts')
-rw-r--r--date-fns/src/isLeapYear/test.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/date-fns/src/isLeapYear/test.ts b/date-fns/src/isLeapYear/test.ts
new file mode 100644
index 0000000..95f5cc5
--- /dev/null
+++ b/date-fns/src/isLeapYear/test.ts
@@ -0,0 +1,42 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+import isLeapYear from '.'
+
+describe('isLeapYear', function() {
+ it('returns true if the given date is in the leap year', function() {
+ const result = isLeapYear(new Date(2012, 6 /* Jul */, 2))
+ assert(result === true)
+ })
+
+ it('returns false if the given date is not in the leap year', function() {
+ const result = isLeapYear(new Date(2014, 6 /* Jul */, 2))
+ assert(result === false)
+ })
+
+ it('works for the years divisible by 100 but not by 400', function() {
+ const result = isLeapYear(new Date(2100, 6 /* Jul */, 2))
+ assert(result === false)
+ })
+
+ it('works for the years divisible by 400', function() {
+ const result = isLeapYear(new Date(2000, 6 /* Jul */, 2))
+ assert(result === true)
+ })
+
+ it('accepts a timestamp', function() {
+ var date = new Date(2012, 6 /* Jul */, 2).getTime()
+ const result = isLeapYear(date)
+ assert(result === true)
+ })
+
+ it('returns false if the given date is `Invalid Date`', function() {
+ const result = isLeapYear(new Date(NaN))
+ assert(result === false)
+ })
+
+ it('throws TypeError exception if passed less than 1 argument', function() {
+ assert.throws(isLeapYear.bind(null), TypeError)
+ })
+})