Skip to content

Commit

Permalink
tests: Add failing locale test: bad value is parsed using default locale
Browse files Browse the repository at this point in the history
Parsing `valueEn` as a Portugese date should fail, but accidentally
gets parsed using the default/en-US locale, because parseDate
internally retries and accidentally omits[^1] the original locale
option that time around.


[^1]: https://github.com/Hacker0x01/react-datepicker/blob/5c1d6d923931535f105f3dddbb6f3e10fd8dd25c/src/date_utils.js#L121
  • Loading branch information
maranomynet committed Jan 19, 2023
1 parent 6c90290 commit 45ce1fa
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/date_utils_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,29 @@ describe("date_utils", function () {
assert(isEqual(actual, expected));
});

it("should parse date based on locale w/o strict", () => {
const valuePt = "26. fev 1995";
const valueEn = "26. feb 1995";

const locale = "pt-BR";
const dateFormat = "d. MMM yyyy";

const expected = new Date(1995, 1, 26);

assert(
isEqual(parseDate(valuePt, dateFormat, locale, false), expected),
"valuePT with pt-BR"
);
assert(
isEqual(parseDate(valueEn, dateFormat, null, false), expected),
"valueEn with default (en-US)"
);
expect(
parseDate(valueEn, dateFormat, locale, false),
"valuePt with default (en-US)"
).to.be.null;
});

it("should not parse date based on locale without a given locale", () => {
const value = "26/05/1995";
const dateFormat = "P";
Expand Down

0 comments on commit 45ce1fa

Please sign in to comment.