tj / should.js

BDD style assertions for node.js -- test framework agnostic
MIT License
2.75k stars 195 forks source link

What is the proper way to check for equality? #93

Closed Broham closed 11 years ago

Broham commented 11 years ago

I have been having some trouble checking for equality of numbers. I have the following check witch always fails:

            it "should have the correct amount of left blanks", ->
                console.log answer_data.summary.data.leftblank
                answer_data.summary.data.leftblank.valueOf().should.eql(4)

The logging shows what I would expect, the number 4. But for some reason this always fails. I have also tried the following:

answer_data.summary.data.leftblank.valueOf().should.equal(4)
answer_data.summary.data.leftblank.valueOf().should.eql("4")
answer_data.summary.data.leftblank.should.eql(4)

but none work. I was finally able to get it working with the following line:

answer_data.summary.data.leftblank.should.valueOf().should.match(/4/)

But it seems odd that none of the above worked. What would be the correct way to do this?

tj commented 11 years ago

.equal() is effectively ===, and .eql() is an algorithm similar to node's assert.deepEquals()

Broham commented 11 years ago

Shouldn't one of the methods that I tried work then? Why is using a regex match the only way I can successfully test equality?

tj commented 11 years ago

well what is that value?