mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-27 18:52:14 +03:00
🐛 Fixed error rendering count with no number (#13)
refs https://github.com/TryGhost/Team/issues/2221 - added guard to `formatNumber` helper used in the `<Count>` component via the `<ContentTitle>` component so a missing count prop is handled gracefully
This commit is contained in:
parent
cb6bf40f56
commit
fcf8570393
@ -23,6 +23,10 @@ export function isSentryEventAllowed({event: sentryEvent}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function formatNumber(number) {
|
export function formatNumber(number) {
|
||||||
|
if (number !== 0 && !number) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
// Adds in commas for separators
|
// Adds in commas for separators
|
||||||
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||||
}
|
}
|
||||||
|
19
apps/comments-ui/src/utils/helpers.test.js
Normal file
19
apps/comments-ui/src/utils/helpers.test.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import * as helpers from './helpers';
|
||||||
|
|
||||||
|
describe('formatNumber', function () {
|
||||||
|
it('adds commas to large numbers', function () {
|
||||||
|
expect(helpers.formatNumber(1234567)).toEqual('1,234,567');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles 0', function () {
|
||||||
|
expect(helpers.formatNumber(0)).toEqual('0');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles undefined', function () {
|
||||||
|
expect(helpers.formatNumber()).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('handles null', function () {
|
||||||
|
expect(helpers.formatNumber(null)).toEqual('');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user