Skip to content

Commit

Permalink
style: Tidy up parseDate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
maranomynet committed Jan 19, 2023
1 parent 5c1d6d9 commit 6c90290
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions test/date_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,16 +884,6 @@ describe("date_utils", function () {
expect(parseDate(value, dateFormat, null, true)).to.not.be.null;
});

it("should parse date based on locale", () => {
const value = "26/05/1995";
const dateFormat = "P";

const expected = new Date("05/26/1995");
const actual = parseDate(value, dateFormat, "pt-BR", true);

assert(isEqual(actual, expected));
});

it("should parse date that matches one of the formats", () => {
const value = "01/15/2019";
const dateFormat = ["MM/dd/yyyy", "yyyy-MM-dd"];
Expand Down Expand Up @@ -922,12 +912,24 @@ describe("date_utils", function () {
expect(parseDate(value, dateFormat, null, false)).to.not.be.null;
});

it("should parse date based on locale", () => {
const value = "26/05/1995";
const locale = "pt-BR";
const dateFormat = "P";

const expected = new Date(1995, 4, 26);
const actual = parseDate(value, dateFormat, locale, true);

assert(isEqual(actual, expected));
});

it("should parse date based on locale without strict parsing", () => {
const value = "26/05/1995";
const locale = "pt-BR";
const dateFormat = "P";

const expected = new Date("05/26/1995");
const actual = parseDate(value, dateFormat, "pt-BR", false);
const expected = new Date(1995, 4, 26);
const actual = parseDate(value, dateFormat, locale, false);

assert(isEqual(actual, expected));
});
Expand All @@ -943,10 +945,11 @@ describe("date_utils", function () {

it("should parse date based on default locale", () => {
const value = "26/05/1995";
const locale = "pt-BR";
const dateFormat = "P";

const expected = new Date("05/26/1995");
setDefaultLocale("pt-BR");
const expected = new Date(1995, 4, 26);
setDefaultLocale(locale);
const actual = parseDate(value, dateFormat, null, false);
setDefaultLocale(null);

Expand Down

0 comments on commit 6c90290

Please sign in to comment.