diff --git a/source/utils.js b/source/utils.js index f80f5b52e..bcdec5ce4 100644 --- a/source/utils.js +++ b/source/utils.js @@ -23,8 +23,9 @@ export let getIframeOption = (optionName: string) => { ) } -// By luck this works as expected for both null and undefined, * but with different branches failing :O * -export let isFloat = (n: number) => Number(n) === n && n % 1 !== 0 +export function isNumeric(val: number) { + return Number(parseFloat(val)) === val +} export function debounce( timeout: number, diff --git a/test/mecanisms.test.js b/test/mecanisms.test.js index ed82766b3..1433d56b7 100644 --- a/test/mecanisms.test.js +++ b/test/mecanisms.test.js @@ -10,7 +10,7 @@ import { analyse, parseAll } from '../source/engine/traverse' import { collectMissingVariables } from '../source/engine/generateQuestions' import testSuites from './load-mecanism-tests' import * as R from 'ramda' -import { isFloat } from '../source/utils' +import { isNumeric } from '../source/utils' describe('Mécanismes', () => testSuites.map(suite => @@ -45,8 +45,7 @@ describe('Mécanismes', () => missing = collectMissingVariables(analysis.targets), target = analysis.targets[0] - // console.log('JSON.stringify(analysis', JSON.stringify(analysis)) - if (isFloat(valeur)) { + if (isNumeric(valeur)) { expect(target.nodeValue).to.be.closeTo(valeur, 0.001) } else if (valeur !== undefined) { expect(target).to.have.property('nodeValue', valeur)