Skip to content

Commit

Permalink
Added a round-trip test for formatting and parsing dates in all locales
Browse files Browse the repository at this point in the history
  • Loading branch information
sunesimonsen committed Sep 13, 2019
1 parent 555ff27 commit 15949b1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/test/locales.test.js
@@ -0,0 +1,34 @@
/* eslint-env mocha */

import path from 'path'
import assert from 'power-assert'
import Chance from 'chance'
import format from '../../src/format'
import parse from '../../src/parse'

import listLocales from '../../scripts/_lib/listLocales'

const chance = new Chance(42)

listLocales().forEach(({ name, code }) => {
describe(`${name}`, () => {
chance.n(chance.date, 1).forEach(date => {
it(`parse(format(${date.toISOString()})) = ${date.toISOString()}`, () => {
const locale = require(path.join('..', '..', 'src', 'locale', code))
const formattedDate = format(
date,
locale.formatLong.date({ width: 'long' }),
{ locale }
)

const parsedDate = parse(formattedDate, 'PP', date, { locale })
console.log(formattedDate, parsedDate)

assert.deepEqual(
parsedDate.toLocaleDateString(),
date.toLocaleDateString()
)
})
})
})
})

0 comments on commit 15949b1

Please sign in to comment.