From a6b91770ae4a4558635c06feb4b7ae377705a44a Mon Sep 17 00:00:00 2001 From: martind2000 Date: Sun, 10 Apr 2016 11:45:44 +0100 Subject: [PATCH] 0.0.3 Added tests --- lib/md-utils.js | 5 +++-- test/md-utils.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 2 deletions(-) create mode 100644 test/md-utils.js diff --git a/lib/md-utils.js b/lib/md-utils.js index d50d114..c0cbc38 100644 --- a/lib/md-utils.js +++ b/lib/md-utils.js @@ -1,3 +1,4 @@ +'uses strict'; /** * * * User: Martin Donnelly @@ -20,7 +21,7 @@ module.exports = { var rObj = {}; for (var item in source) { if (source.hasOwnProperty(item)) { - let newName = item.replace('_', '-'); + var newName = item.replace('_', '-'); rObj[newName] = source[item]; } } @@ -30,7 +31,7 @@ module.exports = { var rObj = {}; for (var item in source) { if (source.hasOwnProperty(item)) { - let newName = item.replace('-', '_'); + var newName = item.replace('-', '_'); rObj[newName] = source[item]; } } diff --git a/test/md-utils.js b/test/md-utils.js new file mode 100644 index 0000000..d0354c8 --- /dev/null +++ b/test/md-utils.js @@ -0,0 +1,56 @@ +var $U = require('../lib/md-utils'); +var assert = require('assert'); + +var dashedObj = { + notdashed: 0, + 'is-dashed': 1, + 'also-dashed': 2 +}; + +var notdashedObj = { + notdashed: 0, + isnotdashed: 1, + alsonotdashed: 2 +}; + +var underScoredObj = { + notdashed: 0, + is_dashed: 1, + also_dashed: 2 +}; + +describe('unDashObject', function() { + it('converts an object with dashes to underscores ', function(done) { + + var updateData = $U.unDashObject(dashedObj); + + assert.deepEqual(updateData, underScoredObj); + done(); + }); + + it('converts an object with no dashes correctly', function(done) { + + var updateData = $U.unDashObject(notdashedObj); + + assert.deepEqual(updateData, notdashedObj); + done(); + }); +}); + +describe('reDashObject', function() { + it('converts an object with underscores to dashes ', function(done) { + + var updateData = $U.reDashObject(underScoredObj); + + assert.deepEqual(updateData, dashedObj); + done(); + }); + + it('converts an object with no underscores correctly', function(done) { + + var updateData = $U.reDashObject(notdashedObj); + + assert.deepEqual(updateData, notdashedObj); + done(); + }); +});