Opened 8 years ago
Closed 8 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: |
Description
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 8 years ago by
comment:2 Changed 8 years ago by
Owner: | set to haysmark |
---|---|
Status: | new → assigned |
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 8 years ago by
Milestone: | tbd → 1.9 |
---|---|
Priority: | undecided → low |
I'm surprised you are using undefined instead of null in your code.
comment:4 Changed 8 years ago by
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.
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.