Skip to content

Commit 883353c

Browse files
maranomynetlaug
authored andcommitted
tests: Add failing locale test: bad value is parsed using default locale
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
1 parent f735e60 commit 883353c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/test/date_utils_test.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,22 @@ describe("date_utils", () => {
10141014
expect(actual).toEqual(expected);
10151015
});
10161016

1017+
it("should parse date based on locale w/o strict", () => {
1018+
const valuePt = "26. fev 1995";
1019+
const valueEn = "26. feb 1995";
1020+
1021+
const locale = "pt-BR";
1022+
const dateFormat = "d. MMM yyyy";
1023+
1024+
const expected = new Date(1995, 1, 26);
1025+
1026+
expect(parseDate(valuePt, dateFormat, locale, false)).toEqual(expected);
1027+
expect(parseDate(valueEn, dateFormat, undefined, false)).toEqual(
1028+
expected,
1029+
);
1030+
expect(parseDate(valueEn, dateFormat, locale, false)).toBeNull();
1031+
});
1032+
10171033
it("should not parse date based on locale without a given locale", () => {
10181034
const value = "26/05/1995";
10191035
const dateFormat = "P";

0 commit comments

Comments
 (0)