2

I expected that JSTD treated "000011" (string) as not equal to 11 (number).

But, taking a look at he actual JSTD code, assertEquals returns

(a === e) 

only if one of the elements are Objects, otherwise returns

(a == e)

isn't this wrong?

Pierpaolo
  • 567
  • 3
  • 7
  • 17
  • 3
    I don't think it's "wrong". They just have a different interpretation of what "equals" means. And since JavaScript provides `==` there must be a way to test this. If you want strict comparison, try `assertSame` (though I don't know if that is what you want, according to the documentation it seems to be the closest though). – Felix Kling May 24 '12 at 15:36
  • http://code.google.com/p/js-test-driver/wiki/Assertions – jbabey May 24 '12 at 15:38
  • "assertSame Fails if the expected and actual values are not references to the same object.", which is not what I want. I was expecting that assertSame did also a type check. – Pierpaolo May 24 '12 at 15:47
  • 1
    @Pierpaolo: Have you tried using primitive values with `assertSame`? – Felix Kling May 24 '12 at 15:55
  • @FelixKling: how do you mean? can you write an example? Noah's answer surely helps. But still, the question remains: why assertEquals has been implemented that way? – Pierpaolo May 25 '12 at 07:23
  • I mean have you tried `assertSame("11", 11)` and `assertSame(11, 11)`? But if *why assertEquals has been implemented that way* is your question, why don't you send an email to the developer? – Felix Kling May 25 '12 at 09:54
  • assertSame works the way I expected assertEquals to work... mmm... this dazzles me a bit... – Pierpaolo May 25 '12 at 13:17

1 Answers1

2

I can't really answer your main question (whether the assertion implementation is "wrong"), but to get at what you are trying to do, you can always write an assertion as such:

var str = '000011';
var num = 11;

assertTrue(str !== num);

Or if you want to ensure that the two variables have the same value and type:

assertTrue(str === num);
Noah Freitas
  • 17,240
  • 10
  • 50
  • 67
  • I guess this is the closest to my goal: to test whether a function that should return a string actually returns a string. – Pierpaolo May 25 '12 at 07:21