Automattic / expect.js

Minimalistic BDD-style assertions for Node.JS and the browser.
2.11k stars 209 forks source link

Support comparison of boxed types #57

Open ELLIOTTCABLE opened 11 years ago

ELLIOTTCABLE commented 11 years ago

Since threequality obviously doesn't cover boxed natives, I expected .eql() to do so, but it doesn't:

expect( new String('foo') ).to.eql('foo')

Error: expected { '0': 'f', '1': 'o', '2': 'o' } to sort of equal 'foo'
 at Assertion.assert (…proj/node_modules/expect.js/expect.js:99:13)
 at Assertion.eql (…proj/node_modules/expect.js/expect.js:214:10)

Either .eql() should inherently support comparing boxed-types to natives, or we need a form of test that is directly equivalent to ==. At the moment, all I can do is the following, which is more than a little awkward:

expect( (new String('foo')) == 'foo' ).to.be.ok()
ELLIOTTCABLE commented 11 years ago

To boot, there's literally no way of doing this in CoffeeScript (see: jashkenas/coffee-script#1693) that isn't half-a-line-long, as it compiles == into ===, and provides no coercive operator at all.

This is completely unacceptable:

expect( (new String 'foo').valueOf() == 'foo' ).to.be.ok()
calvino commented 11 years ago

I agree. I just ran into this problem today and it's really unacceptable that CoffeeScript can't handle boxed type comparisons and also completely removed type coercion. At the very least, double equals in CoffeeScript should treat a new String as a 'string.'