Skip to content

Commit

Permalink
test: Add tests for formatLocallyDistanceToNowStrict
Browse files Browse the repository at this point in the history
  • Loading branch information
PolariTOON committed Dec 21, 2022
1 parent ff6b565 commit 0490f12
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 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 @@ -45,3 +49,37 @@ describe('formatLocallyDistanceToNow', () => {
expect(result).toEqual('about 1 month')
})
})

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

const result = formatLocallyDistanceToNowStrict(date)

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

it('should formatDistanceToNowStrict with medium value', () => {
const date = Date.now() + (44 * 60 + 31) * 1000 // 44min 31s

const result = formatLocallyDistanceToNowStrict(date)

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

it('should formatDistanceToNowStrict with high value', () => {
const date = Date.now() + (89 * 60 + 31) * 1000 // 89min 31s

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 // 42d

const result = formatLocallyDistanceToNowStrict(date)

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

0 comments on commit 0490f12

Please sign in to comment.