moment.test.ts 605 B

123456789101112131415161718192021
  1. import { describe, expect, it } from "vitest";
  2. import moment from "moment";
  3. function timeFormat(time: any) {
  4. return moment(time).format("YYYY-MM-DD HH:mm:ss");
  5. }
  6. describe("momentTest", () => {
  7. it("test moment format", () => {
  8. const date = {
  9. timestampt: 1649302583396,
  10. timeString: "2022-04-07 11:36:23",
  11. dateObj: new Date(1649302583396),
  12. };
  13. const eqTimeStr = "2022-04-07 11:36:23";
  14. expect(timeFormat(date.timestampt)).toEqual(eqTimeStr);
  15. expect(timeFormat(date.timeString)).toEqual(eqTimeStr);
  16. expect(timeFormat(date.dateObj)).toEqual(eqTimeStr);
  17. });
  18. });