From 80cabee66b84e59c8669233c2153b8d27c13e0c6 Mon Sep 17 00:00:00 2001 From: tina Date: Mon, 3 Sep 2018 13:07:40 +0200 Subject: [PATCH] adds more meaningful messages to assertion errors --- lib/sympto/index.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/sympto/index.js b/lib/sympto/index.js index ccfbf32..9281d5d 100644 --- a/lib/sympto/index.js +++ b/lib/sympto/index.js @@ -100,20 +100,20 @@ export default function getSymptoThermalStatus(cycleInfo) { function throwIfArgsAreNotInRequiredFormat(cycles) { cycles.forEach(cycle => { - assert.ok(Array.isArray(cycle)) - assert.ok(cycle.length > 0) //what about 2 cycles of 1 day each?! - assert.ok(cycle[0].bleeding !== null) - assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value") - assert.equal(typeof cycle[0].bleeding.value, 'number') + assert.ok(Array.isArray(cycle), "Cycles must be arrays.") + assert.ok(cycle.length > 0, "Cycle must not be empty.") //what about 2 cycles of 1 day each?! + assert.ok(cycle[0].bleeding !== null, "First cycle day should have bleeding.") + assert.equal(typeof cycle[0].bleeding, 'object', "First cycle day must contain bleeding value.") + assert.equal(typeof cycle[0].bleeding.value, 'number', "First cycle day bleeding value is a number.") cycle.forEach(day => { - assert.equal(typeof day.date, 'string') - assert.doesNotThrow(() => LocalDate.parse(day.date)) - if (day.temperature) assert.equal(typeof day.temperature.value, 'number') - if (day.mucus) assert.equal(typeof day.mucus.value, 'number') - if (day.mucus) assert.ok(day.mucus.value >= 0) - if (day.mucus) assert.ok(day.mucus.value < 5) - if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean') - if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean') + assert.equal(typeof day.date, 'string', "Date is given as a string.") + assert.doesNotThrow(() => LocalDate.parse(day.date), "Date is given in right string format.") + if (day.temperature) assert.equal(typeof day.temperature.value, 'number', "Temperature value is a number.") + if (day.mucus) assert.equal(typeof day.mucus.value, 'number', "Mucus value is a number.") + if (day.mucus) assert.ok(day.mucus.value >= 0, "Mucus value is greater or equal to 0.") + if (day.mucus) assert.ok(day.mucus.value < 5, "Mucus value below 5.") + if (day.cervix) assert.equal(typeof day.cervix.isClosed, 'boolean', "Cervic.isClosed is a boolean.") + if (day.cervix) assert.equal(typeof day.cervix.isHard, 'boolean', "Cervic.isHard is a boolean.") }) }) }