UNPKG

@cainiaofe/cn-ui-m

Version:
31 lines (30 loc) 1.23 kB
import dayjs from 'dayjs'; import { formatValue } from '../format-value'; describe('formatValue', function () { test('should return the formatted value when a single date is passed', function () { var date = dayjs('2022-01-01'); var format = 'YYYY-MM-DD'; var result = formatValue(date, format); expect(result).toBe('2022-01-01'); }); test('should return an array of formatted values when an array of dates is passed', function () { var dates = [ dayjs('2022-01-01'), dayjs('2022-01-02'), dayjs('2022-01-03'), ]; var format = 'YYYY-MM-DD'; var result = formatValue(dates, format); expect(result).toEqual(['2022-01-01', '2022-01-02', '2022-01-03']); }); test('should return undefined when no value is passed', function () { var result = formatValue(undefined, 'YYYY-MM-DD'); expect(result).toBeUndefined(); }); test('should return the result of the custom formatter function', function () { var date = dayjs('2022-01-01'); var format = function (d) { return d.year(); }; var result = formatValue(date, format); expect(result).toBe(2022); }); });