I don't know JSUnit, but how about using toString()
?
assertEquals(mynode.onclick.toString(), "function( ){ return true; }");
Of course, there is an issue with string equality. But with a bit of effort, you could be able to get rid of all whitespaces in these two strings and compare without tabs, spaces, newlines...
I don't think you can compare methods/functions in javascript. If you want to compare two functions, you are in fact comparing their references. That means, once you state even exactly same function on different place in code, it is treated as different function (it has different address).
Check out this for more info about equality The Strict Equality Operators
EDIT: you can try to write the test this way, but there is still possibility of getting false
:
var myHandler = function() { return true; };
MyLibrary.attachEvent( mynode, "click", myHandler);
assertEquals(mynode.onclick, myHandler);
since you're using exact same function, which has same reference in both cases you're using it. However, you must be careful about what MyLibrary.attachEvent
does with passed reference to myHandler
(like is it copying it? extending? just saving reference?...)