From af9fdfa224d28ecbf958221b720cb3fe5979f8e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rodrigo=20Ram=C3=ADrez=20Norambuena?= Date: Tue, 28 Mar 2017 22:15:48 -0300 Subject: [PATCH] Add roundValue unit test function currentweather module: - tests for this.config.roundTemp is false --- tests/unit/functions/currentweather_spec.js | 53 ++++++++++++++++----- 1 file changed, 41 insertions(+), 12 deletions(-) diff --git a/tests/unit/functions/currentweather_spec.js b/tests/unit/functions/currentweather_spec.js index 6252777d..8744fce2 100644 --- a/tests/unit/functions/currentweather_spec.js +++ b/tests/unit/functions/currentweather_spec.js @@ -7,21 +7,23 @@ var vm = require("vm"); describe("Functions module currentweather", function() { - // Fake for use by calendar.js - Module = {} - Module.definitions = {}; - Module.register = function (name, moduleDefinition) { - Module.definitions[name] = moduleDefinition; - }; - config = {}; + before(function(){ + Module = {}; + config = {}; + Module.definitions = {}; + Module.register = function (name, moduleDefinition) { + Module.definitions[name] = moduleDefinition; + }; + require("../../../modules/default/currentweather/currentweather.js"); + Module.definitions.currentweather.config = {}; + }); describe("roundValue", function() { - describe("this.config.roundTemp is true", function() { - // load currentweather - require("../../../modules/default/currentweather/currentweather.js"); - Module.definitions.currentweather.config = {}; - Module.definitions.currentweather.config.roundTemp = true; + describe("this.config.roundTemp is true", function() { + before(function(){ + Module.definitions.currentweather.config.roundTemp = true; + }); var values = [ // index 0 value @@ -41,5 +43,32 @@ describe("Functions module currentweather", function() { }); }); }); + + + describe("this.config.roundTemp is false", function() { + + before(function(){ + Module.definitions.currentweather.config.roundTemp = false; + }); + + var values = [ + // index 0 value + // index 1 expect + [1 , "1.0"], + [1.0 , "1.0"], + [1.02 , "1.0"], + [10.12 , "10.1"], + [2.0 , "2.0"], + ["2.12" , "2.1"], + [10.1 , "10.1"], + [10.10 , "10.1"] + ] + + values.forEach(value => { + it(`for ${value[0]} should be return ${value[1]}`, function() { + expect(Module.definitions.currentweather.roundValue(value[0])).to.equal(value[1]); + }); + }); + }); }); });