0

I'm using JsTestDriver to test, and develop, something in Javascript.

I'm having, periodically, this kind of AssertError:

 expected [object] but was {...}

Some other times, it could be:

 expected [object] but was [object]

And finally, it can also be:

 expected {x=1,...} but was {x=2,...}

So, I've concluded that [object] would be the 'instance' of the object I've created with the 'new' keyword. The collection, that represents each properties of the object could be a copied version of the original object.

If that so, does that mean that when I'm in a situation like this:

function() {
    ...
    var obj1 = fctThatReturnsAnObject();
    obj2.addChild(obj1);
    ...
};

since the obj1 is a variable inside the scope of the function, it would make a copy collection of the original object?

If that's the case, is there a way to get the object by reference and not make a collection copy of it?

Thanks!

P.S.: An extension to this question would be: how to change the '[object]' for some more useful information?

HexaGridBrain
  • 522
  • 7
  • 24

1 Answers1

0

The solution I've come up with is this:

At first, I've changed the obj.prototype.toString = function() {} to return a string that showed the important informations. But when you run a test, the assertSame("...", obj1, obj2) seems to not use the toString function when 2 [object] are not the Same.

So, the next best thing I can think of: is to add --captureConsole when we run the tests and console.log(obj1) and console.log(obj2) to understand which object is what.

 java -jar JsTestDriver --captureConsole --tests all 
HexaGridBrain
  • 522
  • 7
  • 24