import { format, getDaysInMonth, getMonth, getYear, isValid, parse } from "date-fns";
export class DateService {
public getDaysInMonth(month?: Date) {
return getDaysInMonth(month || new Date());
}
describe("DateService", () => {
const dateService = new DateService();
然后测试结果:
it("should return the number of days", () => {
const month = new Date(2022, 4); // May 2022
const daysInMonth = dateService.getDaysInMonth(month);
expect(daysInMonth).toBe(31);
});
2条答案
按热度按时间kmb7vmvb1#
导入类:
设置描述块并示例化DateService
然后测试结果:
atmip9wb2#