Opened 7 years ago

Closed 6 years ago

#15839 closed defect (fixed)

DOH assertEquals function deal with undefined in object in a incorrect way.

Reported by: Programus Owned by: haysmark
Priority: low Milestone: 1.9
Component: TestFramework Version: 1.7.0
Keywords: Cc:
Blocked By: Blocking:


When I compare two objects with properties which value is undefined, the doh.assertEquals gives incorrect results. Here are some examples:

doh.assertEqual({a:undefined, b:'b'},{a:undefined, b:'b'}); // AssertFailure

doh.assertEqual({a:null, b:'b'},{a:undefined, b:'b'}); // true

doh.assertEqual({a:undefined, b:'b'},{a:null, b:'b'}); // AssertFailure

doh.assertEqual({a:undefined, b:'b'},{b:'b'}); // true

doh.assertEqual({a:null, b:'b'},{a:null, b:'b'}); // true <- this makes sense
doh.assertEqual({a:undefined},{a:undefined}); // AssertFailure

doh.assertEqual({a:null},{a:undefined}); // true

doh.assertEqual({a:undefined},{a:null}); // AssertFailure

doh.assertEqual({a:undefined},{}); // true

doh.assertEqual({a:null},{a:null}); // true <- this makes sense

Change History (5)

comment:1 Changed 7 years ago by Programus

One supplement about the version. In the package.json file under doh folder, there is a version information said "1.7.0dev", but the doh and utils are extracted from the 1.7.3 SDK source zip file.

comment:2 Changed 7 years ago by haysmark

Owner: set to haysmark
Status: newassigned

The original code for comparing objects was just:

doh._objPropEq = function(expected, actual){
	for(var x in expected){
		if(!doh.assertEqual(expected[x], actual[x])){
			return false;
	return true;

This was a sound but not complete comparison. In trunk on line 990 in runner.js doh._objPropEq wolfram tried to make the comparison complete:

for(x in actual){ // Lets check "actual" here, expected is checked below.
	if(expected[x] === undefined){
		return false;

I suspect this code is what causes things to break. I wonder if a better test would be to enumerate the keys in a for-in loop and verify the keys are the same.

comment:3 Changed 7 years ago by haysmark

Milestone: tbd1.9
Priority: undecidedlow

I'm surprised you are using undefined instead of null in your code.

comment:4 Changed 6 years ago by bill

Sounds like just need to say !(x in expected) rather than expected[x] === undefined. I'll check that in, in the interests of closing this ticket.

comment:5 Changed 6 years ago by bill

Resolution: fixed
Status: assignedclosed

In [30843]:

fix logic for comparing objects in DOH, fixes #15839 !strict

Note: See TracTickets for help on using tickets.