Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(jest): increase coverage for time utilities #4903

Merged
merged 3 commits into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions utilities/Timezone.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Timezone from './Timezone'

describe('init', () => {
test.skip('getTimezoneDropdowns', () => {
describe('Test utilities/timezone', () => {
test('getTimezoneDropdowns for Singapore', () => {
const result = Timezone.getTimezoneDropdowns()
const nonDaylightTimezone = result.find((obj) => {
return obj.alternativeName === 'Singapore Time'
Expand Down
25 changes: 25 additions & 0 deletions utilities/duration.test.ts
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')
})
})