зеркало из https://github.com/telerik/kendo-intl.git
fix: return empty string if null or undefined value is passed
This commit is contained in:
Родитель
6da228a588
Коммит
bc4eba1212
|
@ -176,6 +176,9 @@ formatters.Q = formatQuarter;
|
|||
|
||||
export default function formatDate(date, format, locale = "en") {
|
||||
if (!isDate(date)) {
|
||||
if (date === undefined || date === null) {
|
||||
return '';
|
||||
}
|
||||
return date;
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ export function toString(value, format, locale) {
|
|||
}
|
||||
}
|
||||
|
||||
return value !== undefined ? value : "";
|
||||
return value !== undefined && value !== null ? value : "";
|
||||
}
|
||||
|
||||
export function format(format, values, locale) {
|
||||
|
|
|
@ -29,6 +29,11 @@ describe('date formatting', () => {
|
|||
expect(formatDate("foo")).toEqual("foo");
|
||||
});
|
||||
|
||||
it('returns empty string if value is null or undefined', () => {
|
||||
expect(formatDate(undefined)).toEqual("");
|
||||
expect(formatDate(null)).toEqual("");
|
||||
});
|
||||
|
||||
it('applies short date format if no format is set', () => {
|
||||
expect(formatDate(date(2000, 1, 30))).toEqual("1/30/2000");
|
||||
});
|
||||
|
|
|
@ -35,6 +35,10 @@ describe('toString', () => {
|
|||
expect(toString(undefined, "c", "en")).toBe("");
|
||||
});
|
||||
|
||||
it('returns empty string if the value is null', () => {
|
||||
expect(toString(null, "c", "en")).toBe("");
|
||||
});
|
||||
|
||||
it('returns the value if the format is not defined', () => {
|
||||
expect(toString(10)).toBe(10);
|
||||
});
|
||||
|
|
|
@ -47,8 +47,9 @@ describe('formatNumber', () => {
|
|||
expect(formatNumber()).toEqual("");
|
||||
});
|
||||
|
||||
it('should return empty string if null value is passed', () => {
|
||||
it('should return empty string if null or undefined value is passed', () => {
|
||||
expect(formatNumber(null)).toEqual("");
|
||||
expect(formatNumber(undefined)).toEqual("");
|
||||
});
|
||||
|
||||
it('should return value if not finite value is passed', () => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче