Skip to content

Commit

Permalink
test: add Japanese locale unit tests (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
zoshigayan authored Jan 3, 2021
1 parent f2e4790 commit f9d79d5
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/locale/ja.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import MockDate from 'mockdate'
import moment from 'moment'
import dayjs from '../../src'
import relativeTime from '../../src/plugin/relativeTime'
import '../../src/locale/ja'

dayjs.extend(relativeTime)

beforeEach(() => {
MockDate.set(new Date())
})

afterEach(() => {
MockDate.reset()
})

it('Finnish locale relative time in past and future', () => {
const cases = [
[1, 'd', '1日後'],
[-1, 'd', '1日前'],
[2, 'd', '2日後'],
[-2, 'd', '2日前'],
[10, 'd', '10日後'],
[-10, 'd', '10日前'],
[6, 'm', '6分後'],
[-6, 'm', '6分前'],
[5, 'h', '5時間後'],
[-5, 'h', '5時間前'],
[3, 'M', '3ヶ月後'],
[-3, 'M', '3ヶ月前'],
[4, 'y', '4年後'],
[-4, 'y', '4年前']
]
cases.forEach((c) => {
expect(dayjs().add(c[0], c[1]).locale('ja').fromNow())
.toBe(c[2])
expect(dayjs().add(c[0], c[1]).locale('ja').fromNow())
.toBe(moment().add(c[0], c[1]).locale('ja').fromNow())
})
expect(dayjs().add(-10, 'd').locale('ja').fromNow(true))
.toBe('10日')
expect(dayjs().add(-10, 'd').locale('ja').fromNow(true))
.toBe(moment().add(-10, 'd').locale('ja').fromNow(true))
})

0 comments on commit f9d79d5

Please sign in to comment.