Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sakamossan committed Oct 1, 2022
1 parent da83376 commit 9f4f88a
Showing 1 changed file with 52 additions and 1 deletion.
53 changes: 52 additions & 1 deletion src/roundToNearestHours/test.ts
Expand Up @@ -43,7 +43,58 @@ describe('roundToNearestHours', function () {
it('does not mutate the original date', function () {
const date = new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99)
roundToNearestHours(date)
assert.deepStrictEqual(date, new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99))
assert.deepStrictEqual(
date,
new Date(2014, 6 /* Jul */, 10, 12, 10, 10, 99)
)
})

it('rounds according to the passed mode - floor', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 12, 30, 0, 5),
{ roundingMethod: 'floor' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 13, 0, 0))
})

it('rounds according to the passed mode - floor - when nearestTo is provided', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 15, 10, 30, 5),
{ nearestTo: 4, roundingMethod: 'floor' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 16, 0, 0))
})

it('rounds according to the passed mode - ceil', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
{ roundingMethod: 'ceil' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 13, 0, 0))
})

it('rounds according to the passed mode - ceil - when nearestTo is provided', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
{ nearestTo: 4, roundingMethod: 'ceil' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 16, 0, 0))
})

it('rounds according to the passed mode - round - when nearestTo is provided', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
{ nearestTo: 4, roundingMethod: 'round' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 0, 0))
})

it('rounds according to the passed mode - trunc - when nearestTo is provided', () => {
const result = roundToNearestHours(
new Date(2014, 6 /* Jul */, 10, 12, 10, 30, 5),
{ nearestTo: 4, roundingMethod: 'trunc' }
)
assert.deepStrictEqual(result, new Date(2014, 6 /* Jul */, 10, 12, 0, 0))
})

it('returns `Invalid Date` if the given date is invalid', function () {
Expand Down

0 comments on commit 9f4f88a

Please sign in to comment.