UNPKG

@cainiaofe/cn-ui-m

Version:
43 lines (42 loc) 1.92 kB
import { getRangeValid } from '../get-range-valid'; import dayjs from 'dayjs'; describe('getRangeValid', function () { // 测试用例1:空数组 it('should return false for empty array', function () { expect(getRangeValid([])).toBe(false); }); // 测试用例2:非数组参数 it('should return false for non-array input', function () { expect(getRangeValid({})).toBe(false); }); // 测试用例3:只有一个元素的数组 it('should return false for an array with one element', function () { expect(getRangeValid([new Date()])).toBe(false); }); // 测试用例4:开始日期为空 it('should return false when start date is undefined', function () { expect(getRangeValid([undefined, new Date()])).toBe(false); }); // 测试用例5:结束日期为空 it('should return false when end date is undefined', function () { expect(getRangeValid([new Date(), undefined])).toBe(false); }); // 测试用例6:开始日期晚于结束日期 it('should return true when start date is after end date', function () { var startDate = dayjs().add(1, 'day').toDate(); var endDate = dayjs().toDate(); expect(getRangeValid([startDate, endDate])).toBe(true); }); // 测试用例7:有效日期范围 it('should return true for a valid and unequal date range', function () { var startDate = dayjs().subtract(1, 'day').toDate(); var endDate = dayjs().toDate(); expect(getRangeValid([startDate, endDate])).toBe(true); }); // 测试用例8:年月日相同,时分秒不同 it('should return false for start of day and end of day range', function () { var startDate = dayjs().startOf('day').toDate(); var endDate = dayjs().endOf('day').toDate(); expect(getRangeValid([startDate, endDate])).toBe(false); }); });