Skip to content

Commit

Permalink
test: Add tests for formatLocallyDistanceToNow* helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
PolariTOON committed Dec 8, 2022
1 parent ea49d39 commit 01ea93c
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion react/I18n/format.spec.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { initFormat, formatLocallyDistanceToNow } from './format'
import {
initFormat,
formatLocallyDistanceToNow,
formatLocallyDistanceToNowStrict
} from './format'

describe('initFormat', () => {
beforeEach(() => {
Expand Down Expand Up @@ -36,4 +40,46 @@ describe('formatLocallyDistanceToNow', () => {

expect(result).toEqual('about 2 hours')
})

it('should formatDistanceToNow with very high value', () => {
const date = Date.now() + 42 * 24 * 60 * 60 * 1000

const result = formatLocallyDistanceToNow(date)

expect(result).toEqual('about 1 month')
})
})

describe('formatLocallyDistanceToNowStrict', () => {
it('should formatDistanceToNowStrict with small value', () => {
const date = Date.now() + 29 * 1000

const result = formatLocallyDistanceToNowStrict(date)

expect(result).toEqual('29 seconds')
})

it('should formatDistanceToNowStrict with medium value', () => {
const date = Date.now() + 2671 * 1000

const result = formatLocallyDistanceToNowStrict(date)

expect(result).toEqual('45 minutes')
})

it('should formatDistanceToNowStrict with high value', () => {
const date = Date.now() + 5371 * 1000

const result = formatLocallyDistanceToNowStrict(date)

expect(result).toEqual('1 hour')
})

it('should formatDistanceToNowStrict with very high value', () => {
const date = Date.now() + 42 * 24 * 60 * 60 * 1000

const result = formatLocallyDistanceToNowStrict(date)

expect(result).toEqual('1 month')
})
})

0 comments on commit 01ea93c

Please sign in to comment.