From fd8e53b5fa12d5fd5c121edf323df127ec338cd4 Mon Sep 17 00:00:00 2001 From: Mael Date: Sun, 30 Sep 2018 18:38:55 +0000 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20Am=C3=A9lioration=20du?= =?UTF-8?q?=20test=20des=20m=C3=A9canismes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/utils.js | 5 +++-- test/mecanisms.test.js | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) 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)