Back to Repositories

Validating Lithuanian Locale Date Formatting in dayjs

This test suite validates the Lithuanian (lt) locale functionality in Day.js by comparing its date formatting capabilities with Moment.js. The tests ensure accurate month formatting and date display patterns in Lithuanian language across multiple format strings.

Test Coverage Overview

The test suite provides comprehensive coverage of Lithuanian locale date formatting functionality.

  • Tests month formatting across different format patterns
  • Validates day and date formatting in Lithuanian
  • Compares output against Moment.js reference implementation
  • Covers multiple date variations through iteration

Implementation Analysis

The testing approach uses Jest’s expect assertions to compare Day.js and Moment.js outputs systematically.

Key patterns include:
  • Iterative testing over multiple days
  • Multiple format string variations
  • Direct comparison with Moment.js as reference
  • Locale-specific formatting validation

Technical Details

Testing infrastructure includes:

  • Jest testing framework
  • Day.js core library
  • Lithuanian locale plugin
  • Moment.js for comparison
  • Format strings: DD MMMM YYYY MMM, dddd, MMMM D YYYY, MMMM, MMM

Best Practices Demonstrated

The test suite exemplifies several testing best practices.

  • Consistent format string testing
  • Reference implementation comparison
  • Iterative test cases
  • Isolated locale testing
  • Clear test organization

iamkun/dayjs

test/locale/lt.test.js

            
import moment from 'moment'
import dayjs from '../../src'
import '../../src/locale/lt'

it('Format month with locale function', () => {
  for (let i = 0; i <= 7; i += 1) {
    const dayjsUK = dayjs().locale('lt').add(i, 'day')
    const momentUK = moment().locale('lt').add(i, 'day')
    const testFormat1 = 'DD MMMM YYYY MMM'
    const testFormat2 = 'dddd, MMMM D YYYY'
    const testFormat3 = 'MMMM'
    const testFormat4 = 'MMM'
    expect(dayjsUK.format(testFormat1)).toEqual(momentUK.format(testFormat1))
    expect(dayjsUK.format(testFormat2)).toEqual(momentUK.format(testFormat2))
    expect(dayjsUK.format(testFormat3)).toEqual(momentUK.format(testFormat3))
    expect(dayjsUK.format(testFormat4)).toEqual(momentUK.format(testFormat4))
  }
})