[bugfix] prevent d3-format from raising (#6386)

Since https://github.com/apache/incubator-superset/pull/6287 and
effectively moving to a new version of d3, d3-format and d3-time-format
raises when receiving invalid input strings.

This code wraps the potential issues inside `try` blocks that will
effectively return an `ERROR` string as output to the formatting
function.
This commit is contained in:
Maxime Beauchemin
2018-11-14 11:22:06 -08:00
committed by GitHub
parent cb556688ec
commit 4690563d40
3 changed files with 22 additions and 5 deletions

View File

@@ -29,6 +29,7 @@ describe('utils', () => {
expect(d3format('.3s', 1234)).toBe('1.23k');
expect(d3format('.3s', 1237)).toBe('1.24k');
expect(d3format('', 1237)).toBe('1.24k');
expect(d3format('.2efd2.ef.2.e', 1237)).toBe('ERROR');
});
});
@@ -45,8 +46,9 @@ describe('utils', () => {
it('is a function', () => {
expect(typeof d3TimeFormatPreset).toBe('function');
});
it('returns a working time formatter', () => {
it('returns a working formatter', () => {
expect(d3FormatPreset('smart_date')(0)).toBe('1970');
expect(d3FormatPreset('%%GIBBERISH')(0)).toBe('ERROR');
});
});