Skip to content

Commit

Permalink
Pasan tests para #5
Browse files Browse the repository at this point in the history
  • Loading branch information
diegoefe committed Nov 14, 2016
1 parent 73d2289 commit 7692ae2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/discrepances.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ function DiscrepancesTester(tester){
this.message = bestGlobals.functionName(tester);
}

function getName(type, variable, clase) {
return type==='object' && variable.constructor ? constructorName(variable):clase;
}

discrepances = function discrepances(a, b, opts){
opts = changing(defaultOpts, opts||{});
if(a === b){ return null; }
Expand All @@ -221,12 +225,14 @@ discrepances = function discrepances(a, b, opts){
if(typeA==='object' && typeB==='object') {
var classA = getClassOnlyForSomeOfBuiltIns(a, opts);
var classB = getClassOnlyForSomeOfBuiltIns(b, opts);
var nameA = getName(typeA,a,classA);
var nameB = getName(typeB,b,classB);
if(classA !== classB) {
var r = {classes:[classA,classB]};
var r = {classes:[nameA,nameB]};
if(isSimpleValue(classA) && isSimpleValue(classB)) { r.values=[a,b]; }
return r;
} else if(!opts.duckTyping && a.constructor !== b.constructor) {
return {classes:[constructorName(a),constructorName(b)]};
return {classes:[nameA,nameB]};
} else {
return compareClasses(classA, a, b, opts);
}
Expand Down
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe("discrepances", function(){
{a:undefined , b:false , expect:{types:['undefined', 'boolean'], values:[undefined, false]} },
{a:new Example({uno:1}) , b:new Example({uno:1}) , expect:null },
{a:new Example({uno:1}) , b:{uno:1} , expect:{classes:['Example', 'Object']} },
{skip:'#5', a:new Example({uno:1}) , b:[1,2] , expect:{classes:['Example', 'Array']} },
{a:new Example({uno:1}) , b:[1,2] , expect:{classes:['Example', 'Array']} },
{a:new Example({uno:1}) , b:new Example({uno:2}) , expect:{object:{"uno":discrepances(1,2)}} },
{a:{0:1, length:1} , b:{0:1,1:2,length:2} ,
expect:{object:{length:discrepances(1,2), 1:{onlyRight:2}}}
Expand Down

0 comments on commit 7692ae2

Please sign in to comment.