summaryrefslogtreecommitdiff
path: root/date-fns/src/eachMinuteOfInterval/test.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2021-08-23 16:46:06 -0300
committerSebastian <sebasjm@gmail.com>2021-08-23 16:48:30 -0300
commit38acabfa6089ab8ac469c12b5f55022fb96935e5 (patch)
tree453dbf70000cc5e338b06201af1eaca8343f8f73 /date-fns/src/eachMinuteOfInterval/test.ts
parentf26125e039143b92dc0d84e7775f508ab0cdcaa8 (diff)
downloadnode-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.gz
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.tar.bz2
node-vendor-38acabfa6089ab8ac469c12b5f55022fb96935e5.zip
added web vendorsHEADmaster
Diffstat (limited to 'date-fns/src/eachMinuteOfInterval/test.ts')
-rw-r--r--date-fns/src/eachMinuteOfInterval/test.ts99
1 files changed, 99 insertions, 0 deletions
diff --git a/date-fns/src/eachMinuteOfInterval/test.ts b/date-fns/src/eachMinuteOfInterval/test.ts
new file mode 100644
index 0000000..c4dab70
--- /dev/null
+++ b/date-fns/src/eachMinuteOfInterval/test.ts
@@ -0,0 +1,99 @@
+// @flow
+/* eslint-env mocha */
+
+import assert from 'power-assert'
+
+import eachMinuteOfInterval from '.'
+
+describe('eachMinuteOfInterval', () => {
+ it('should return an array of Date objects containing a Date for each minute between the interval', () => {
+ const result = eachMinuteOfInterval({
+ start: new Date(2020, 10, 14, 13, 0),
+ end: new Date(2020, 10, 14, 13, 5)
+ })
+
+ assert.deepEqual(result, [
+ new Date(2020, 10, 14, 13, 0),
+ new Date(2020, 10, 14, 13, 1),
+ new Date(2020, 10, 14, 13, 2),
+ new Date(2020, 10, 14, 13, 3),
+ new Date(2020, 10, 14, 13, 4),
+ new Date(2020, 10, 14, 13, 5)
+ ])
+ })
+
+ it('should handle all the minutes that are not in the begining', () => {
+ const result = eachMinuteOfInterval({
+ start: new Date(2020, 10, 14, 13, 0, 33),
+ end: new Date(2020, 10, 14, 13, 2)
+ })
+
+ assert.deepEqual(result[0], new Date(2020, 10, 14, 13))
+ assert.deepEqual(result[2], new Date(2020, 10, 14, 13, 2))
+ })
+
+ it('should accept timestamps', () => {
+ const start = new Date(2020, 10, 14, 13, 0).getTime()
+ const end = new Date(2020, 10, 14, 13, 2).getTime()
+
+ const result = eachMinuteOfInterval({
+ start,
+ end
+ })
+
+ assert.deepEqual(result, [
+ new Date(2020, 10, 14, 13, 0),
+ new Date(2020, 10, 14, 13, 1),
+ new Date(2020, 10, 14, 13, 2)
+ ])
+ })
+
+ it('throws an exception if the start date is after the end date', () => {
+ const block = eachMinuteOfInterval.bind(null, {
+ start: new Date(2014, 10, 14, 10),
+ end: new Date(2014, 10, 14, 5)
+ })
+ assert.throws(block, RangeError)
+ })
+
+ describe('options.step', () => {
+ const interval = {
+ start: new Date(2020, 9, 14, 13, 1),
+ end: new Date(2020, 9, 14, 13, 7)
+ }
+
+ const stepError = /^RangeError: `options.step` must be a number equal or greater than 1$/
+
+ it('returns an array with starts of hours from the hour of the start date to the hour of the end date with the given step', () => {
+ const result = eachMinuteOfInterval(interval, { step: 3 })
+ assert.deepEqual(result, [
+ new Date(2020, 9, 14, 13, 1),
+ new Date(2020, 9, 14, 13, 4),
+ new Date(2020, 9, 14, 13, 7)
+ ])
+ })
+
+ it('throws TypeError error if `options.step` is less than 1', () => {
+ assert.throws(
+ () => eachMinuteOfInterval(interval, { step: 0 }),
+ stepError
+ )
+ assert.throws(
+ () => eachMinuteOfInterval(interval, { step: -3 }),
+ stepError
+ )
+ })
+
+ it('throws TypeError error if `options.step` is NaN', () => {
+ // $ExpectedMistake
+ assert.throws(
+ () => eachMinuteOfInterval(interval, { step: 'w' }),
+ stepError
+ )
+ assert.throws(
+ () => eachMinuteOfInterval(interval, { step: NaN }),
+ stepError
+ )
+ })
+ })
+})