-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: create unit tests for parse-duration
- Loading branch information
1 parent
6c8d41d
commit cd39739
Showing
3 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { describe, it } from 'node:test' | ||
import assert from 'node:assert/strict' | ||
import { parseDuration } from '@vates/parse-duration/index.js' | ||
|
||
describe('`ms` without magic: always parse a duration and throws if invalid.', () => { | ||
it('should parse string "2 days"', () => { | ||
const input = '2 days' | ||
const expected = 172800000 | ||
assert.strictEqual(parseDuration(input), expected) | ||
}) | ||
|
||
it('should return the same duration if it is already in milliseconds', () => { | ||
const input = 172800000 | ||
const expected = 172800000 | ||
assert.strictEqual(parseDuration(input), expected) | ||
}) | ||
|
||
it('should throw an error for an undefined duration', () => { | ||
const input = undefined | ||
assert.throws(() => parseDuration(input), { message: 'not a valid duration: undefined' }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters