-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
108 additions
and
58 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
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,33 @@ | ||
import { Duration } from '../../../src/index.js'; | ||
|
||
describe('fromString', () => { | ||
test('Parsing simple valid string', () => { | ||
const duration = Duration.fromString('100ms'); | ||
const value = Number(Duration.toMillis(duration)); | ||
expect(value).toBe(100); | ||
}); | ||
|
||
test('Parsing valid string', () => { | ||
const duration = Duration.fromString('10d 1h 2m 7s'); | ||
const value = Number(Duration.toMillis(duration)); | ||
expect(value).toBe(867_727_000); | ||
}); | ||
|
||
test('Fails when using invalid unit for a measure', () => { | ||
expect(() => { | ||
Duration.fromString('1w 10d'); | ||
}).toThrow(); | ||
}); | ||
|
||
test('Fails when using decimals in a measure', () => { | ||
expect(() => { | ||
Duration.fromString('10.0d'); | ||
}).toThrow(); | ||
}); | ||
|
||
test('Fails when using negative numbers in a measure', () => { | ||
expect(() => { | ||
Duration.fromString('-10d'); | ||
}).toThrow(); | ||
}); | ||
}); |