@cainiaofe/cn-ui-m
Version:
19 lines (18 loc) • 1.03 kB
JavaScript
// 编写format的单测测试用例
import { CnDatePickerPro } from "../../../form/cn-date-picker-pro";
import { render } from '@testing-library/react';
import dayjs from 'dayjs';
import React from 'react';
var defaultVal = '2020-02-02';
describe('DateRangeCalendar', function () {
it('should format date correctly with function', function () {
// 测试用例1: 使用函数作为format参数
var getByText = render(React.createElement(CnDatePickerPro, { defaultValue: defaultVal, format: function (day) { return dayjs(day).format('YYYY-MM-DD HH:mm:ss'); } })).getByText;
expect(getByText('2020-02-02 00:00:00')).toBeInTheDocument();
});
it('should format date correctly with string format', function () {
// 测试用例2: 使用字符串作为format参数
var getByText = render(React.createElement(CnDatePickerPro, { defaultValue: defaultVal, format: "YYYY-MM-DD HH:mm:ss" })).getByText;
expect(getByText('2020-02-02 00:00:00')).toBeInTheDocument();
});
});