-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #568 from oasisprotocol/lw/test-date
Test formatDistanceToNow
- Loading branch information
Showing
5 changed files
with
69 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Test formatDistanceToNow |
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
27 changes: 27 additions & 0 deletions
27
src/app/utils/__tests__/__snapshots__/formatDistanceToNow.test.ts.snap
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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`formatDistanceToNow should format future dates 1`] = ` | ||
[ | ||
"1 min", | ||
"1 min", | ||
"20 mins", | ||
"1 hr", | ||
"1 days", | ||
"1 mos", | ||
"1 yr", | ||
"8 mos", | ||
] | ||
`; | ||
|
||
exports[`formatDistanceToNow should format past dates 1`] = ` | ||
[ | ||
"1 min", | ||
"1 min", | ||
"20 mins", | ||
"1 hr", | ||
"1 days", | ||
"1 mos", | ||
"1 yr", | ||
"8 mos", | ||
] | ||
`; |
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,38 @@ | ||
import { formatDistanceToNow } from '../dateFormatter' | ||
|
||
describe('formatDistanceToNow', () => { | ||
beforeEach(() => { | ||
jest.useFakeTimers() | ||
jest.setSystemTime(new Date('2023-01-01T01:01:01Z')) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.useRealTimers() | ||
}) | ||
|
||
it('should format future dates', () => { | ||
expect([ | ||
formatDistanceToNow(new Date('2023-01-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2023-01-01T01:01:21Z')), | ||
formatDistanceToNow(new Date('2023-01-01T01:21:21Z')), | ||
formatDistanceToNow(new Date('2023-01-01T02:01:01Z')), | ||
formatDistanceToNow(new Date('2023-01-02T01:01:01Z')), | ||
formatDistanceToNow(new Date('2023-02-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2024-01-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2023-08-23T12:20:56Z')), | ||
]).toMatchSnapshot() | ||
}) | ||
|
||
it('should format past dates', () => { | ||
expect([ | ||
formatDistanceToNow(new Date('2023-01-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2023-01-01T01:00:41Z')), | ||
formatDistanceToNow(new Date('2023-01-01T00:41:01Z')), | ||
formatDistanceToNow(new Date('2023-01-01T00:01:01Z')), | ||
formatDistanceToNow(new Date('2022-12-31T01:01:01Z')), | ||
formatDistanceToNow(new Date('2022-12-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2022-01-01T01:01:01Z')), | ||
formatDistanceToNow(new Date('2022-04-23T12:20:56Z')), | ||
]).toMatchSnapshot() | ||
}) | ||
}) |