From 5b0ec76cf8cf6cbf179281eff421ff6e4cbde968 Mon Sep 17 00:00:00 2001 From: "Diego F.(EW7)" Date: Tue, 4 Oct 2016 09:02:47 -0300 Subject: [PATCH] Agrego skip y pasa el primero --- lib/discrepances.js | 2 +- test/test.js | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/discrepances.js b/lib/discrepances.js index de50cc4..4535df0 100644 --- a/lib/discrepances.js +++ b/lib/discrepances.js @@ -28,7 +28,7 @@ var discrepances = {}; discrepances = function discrepances(obj, def){ var rta=''; - if(def.typeof && typeof obj !== def.typeof){ + if(def && def.typeof && typeof obj !== def.typeof){ rta+='typeof '+JSON.stringify(obj)+' !== '+JSON.stringify(def.typeof); } return rta || null; diff --git a/test/test.js b/test/test.js index 6baf5cc..c7e2ce1 100644 --- a/test/test.js +++ b/test/test.js @@ -7,19 +7,23 @@ var discrepances = require('../lib/discrepances.js'); describe("discrepances", function(){ [ {a:4 , b:4 , expected: null }, - {a:4 , b:5 , expected: {difference:-1 , values:[4, 5] }}, - {a:"4" , b:4 , expected: {types:['string', 'number'], values:["4", 4] }}, - {a:null , b:0 , expected: {types:['null' , 'number'], values:[null, 0] }}, - {a:new Date() , b:/a/ , expected: {class:['Date' , 'RegExp'], values:[new Date(), /a/] }}, - {a:new Date(2011,1,3), b:new Date(2011,1,4) , expected: {difference:'a definir', values:[new Date(2011,1,3), new Date(2011,1,4)] }}, - {a:[1,2,3,4,5] , b:[1,2,33,44,5,6] , expected: {array:{length:discrepances(5,6), 2:discrepances(3,33)} }}, - {a:{x:1, y:2} , b:{y:3, z:{zz:3}} , expected: {object:{x:{onlyLeft:1}, y:discrepances(2,3), z:{onlyRight:{zz:3}}} }}, - {a:{x:1, y:2, z:[3]} , b:{x:1, y:2, z:[3]} , expected: null }, + {skip:true, a:4 , b:5 , expected: {difference:-1 , values:[4, 5] }}, + {skip:true, a:"4" , b:4 , expected: {types:['string', 'number'], values:["4", 4] }}, + {skip:true, a:null , b:0 , expected: {types:['null' , 'number'], values:[null, 0] }}, + {skip:true, a:new Date() , b:/a/ , expected: {class:['Date' , 'RegExp'], values:[new Date(), /a/] }}, + {skip:true, a:new Date(2011,1,3), b:new Date(2011,1,4) , expected: {difference:'a definir', values:[new Date(2011,1,3), new Date(2011,1,4)] }}, + {skip:true, a:[1,2,3,4,5] , b:[1,2,33,4,5,6] , expected: {array:{length:discrepances(5,6), 2:discrepances(3,33)} }}, + {skip:true, a:{x:1, y:2} , b:{y:3, z:{zz:3}} , expected: {object:{x:{onlyLeft:1}, y:discrepances(2,3), z:{onlyRight:{zz:3}}} }}, + {skip:true, a:{x:1, y:2, z:[3]} , b:{x:1, y:2, z:[3]} , expected: null }, ].forEach(function(fixture){ + if(fixture.skip) { + it('skipped fixture: '+JSON.stringify(fixture)); + return true; + } it("controls discrepances via fixture: "+JSON.stringify(fixture), function(){ - expect(discrepances(fixture.a, fixture.b)).to.eql(fixture.expect); - expect(JSON.stringify(discrepances(fixture.a, fixture.structure))).to.eql(JSON.stringify(fixture.expect)); - expect(JSON4all.stringify(discrepances(fixture.a, fixture.structure))).to.eql(JSON4all.stringify(fixture.expect)); + expect(discrepances(fixture.a, fixture.b)).to.eql(fixture.expected); + expect(JSON.stringify(discrepances(fixture.a, fixture.structure))).to.eql(JSON.stringify(fixture.expected)); + expect(JSON4all.stringify(discrepances(fixture.a, fixture.structure))).to.eql(JSON4all.stringify(fixture.expected)); }); }); }); \ No newline at end of file