Skip to content

Commit 95b59b6

Browse files
Merge pull request #3582 from YuCJ/master
fix: formatFunc should take source params
2 parents f4a6cfe + ffad421 commit 95b59b6

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/date_utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export function getLocaleObject(localeSpec) {
377377
}
378378

379379
export function getFormattedWeekdayInLocale(date, formatFunc, locale) {
380-
return formatFunc(formatDate(date, "EEEE", locale));
380+
return typeof formatFunc === "function" ? formatFunc(date, locale) : formatDate(date, "EEEE", locale);
381381
}
382382

383383
export function getWeekdayMinInLocale(date, locale) {

test/calendar_test.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,15 @@ describe("Calendar", function () {
162162
});
163163

164164
it("should correctly format weekday using formatWeekDay prop", function () {
165-
const calendar = getCalendar({ formatWeekDay: (day) => day[0] });
165+
const mockFormattedWeekDay = "mockFormattedWeekDay";
166+
const formatWeekDay = sinon.fake.returns(mockFormattedWeekDay);
167+
const calendar = getCalendar({ formatWeekDay });
168+
sinon.assert.alwaysCalledWith(formatWeekDay, sinon.match.date);
166169
calendar
167170
.find(".react-datepicker__day-name")
168-
.forEach((dayName) => expect(dayName.text()).to.have.length(1));
171+
.forEach((dayName) =>
172+
expect(dayName.text()).to.equals(mockFormattedWeekDay)
173+
);
169174
});
170175

171176
it("should contain the correct class when using the weekDayClassName prop", () => {

0 commit comments

Comments
 (0)