Added tests
This commit is contained in:
martind2000 2016-04-10 11:45:44 +01:00
parent d7b028a786
commit a6b91770ae
2 changed files with 59 additions and 2 deletions

View File

@ -1,3 +1,4 @@
'uses strict';
/** /**
* * * *
* User: Martin Donnelly * User: Martin Donnelly
@ -20,7 +21,7 @@ module.exports = {
var rObj = {}; var rObj = {};
for (var item in source) { for (var item in source) {
if (source.hasOwnProperty(item)) { if (source.hasOwnProperty(item)) {
let newName = item.replace('_', '-'); var newName = item.replace('_', '-');
rObj[newName] = source[item]; rObj[newName] = source[item];
} }
} }
@ -30,7 +31,7 @@ module.exports = {
var rObj = {}; var rObj = {};
for (var item in source) { for (var item in source) {
if (source.hasOwnProperty(item)) { if (source.hasOwnProperty(item)) {
let newName = item.replace('-', '_'); var newName = item.replace('-', '_');
rObj[newName] = source[item]; rObj[newName] = source[item];
} }
} }

56
test/md-utils.js Normal file
View File

@ -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();
});
});