From 6b7360e04874fd469b30e9fd516477c258cefdaa Mon Sep 17 00:00:00 2001 From: polemius Date: Tue, 24 Sep 2019 22:28:22 +0200 Subject: [PATCH] chore(widget-number): add float test (#2680) --- .../src/__tests__/number.spec.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/netlify-cms-widget-number/src/__tests__/number.spec.js b/packages/netlify-cms-widget-number/src/__tests__/number.spec.js index 85884bf3..4c1663ad 100644 --- a/packages/netlify-cms-widget-number/src/__tests__/number.spec.js +++ b/packages/netlify-cms-widget-number/src/__tests__/number.spec.js @@ -120,6 +120,18 @@ describe('Number widget', () => { expect(onChangeSpy).toHaveBeenCalledWith(parseInt(testValue, 10)); }); + it('should parse float numbers as float', () => { + const field = fromJS({ ...fieldSettings, valueType: 'float' }); + const testValue = (Math.random() * (20 - -20 + 1) + -20).toFixed(2); + const { input, onChangeSpy } = setup({ field }); + + fireEvent.focus(input); + fireEvent.change(input, { target: { value: String(testValue) } }); + + expect(onChangeSpy).toHaveBeenCalledTimes(1); + expect(onChangeSpy).toHaveBeenCalledWith(parseFloat(testValue)); + }); + it('should allow 0 as a value', () => { const field = fromJS(fieldSettings); const testValue = 0;