Skip to content

Commit

Permalink
Agrego skip y pasa el primero
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Oct 4, 2016
1 parent 52998c1 commit 5b0ec76
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
26 changes: 15 additions & 11 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
});
});

0 comments on commit 5b0ec76

Please sign in to comment.