-
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.
feat(jest): increase coverage for time utilities (#4903)
- Loading branch information
Showing
2 changed files
with
34 additions
and
6 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,25 @@ | ||
import { formatDuration } from '~/utilities/duration' | ||
|
||
Date.now = jest.fn(() => 1656069280) | ||
// Date.setSeconds = jest.fn(() => 1656069280) | ||
let localDate: number | ||
|
||
describe('Test utilities/duration', () => { | ||
beforeAll(() => { | ||
localDate = Date.now() | ||
}) | ||
test('call with latest date', () => { | ||
// const argument = localDate.now() // Get unix timestamp | ||
|
||
const result: any = formatDuration(localDate) | ||
expect(result).toEqual('59:14:40') | ||
}) | ||
test('call with 45 seconds date', () => { | ||
const rawDate = new Date() | ||
const argument = rawDate.setSeconds(45) // Returns unix timestamp | ||
|
||
const result: any = formatDuration(argument) | ||
expect(result).not.toEqual('59:14:40') // Because date is not what we defaulted above | ||
expect(typeof result).toBe('string') | ||
}) | ||
}) |