Skip to content

Commit

Permalink
nuevos tests para discrepances
Browse files Browse the repository at this point in the history
  • Loading branch information
emilioplatzer committed Oct 3, 2016
1 parent 27fccc9 commit bc6a662
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
"use strict";

var assert = require('self-explain').assert;
var JSON4all = require('json4all.js');
var expect = require('expect.js');
var discrepances = require('../lib/discrepances.js');

describe("discrepances", function(){
[
{obj:4 , structure:{typeof: "number"}, expect: null},
{obj:"4", structure:{typeof: "number"}, expect: 'typeof "4" !== "number"'}
{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 },
].forEach(function(fixture){
it("controls discrepances via fixture: "+JSON.stringify(fixture), function(){
eval(assert(discrepances(fixture.obj, fixture.structure) === fixture.expect));
expect(discrepances(fixture.obj, fixture.structure)).to.eql(fixture.expect);
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));
});
});
});

0 comments on commit bc6a662

Please sign in to comment.