tj / should.js

BDD style assertions for node.js -- test framework agnostic

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fails to compare two objects with booleans?

haakonnessjoen opened this issue · comments

var testobj = { bool1: false, bool2: true };
testobj.should.match({ bool1: false, bool2: true });

Using mocha, I get the following output:

  AssertionError: expected { bool1: false, bool2: true } to be { bool1: false, bool2: true }
  + expected - actual

  at Assertion.prop.(anonymous function) (/..../node_modules/should/lib/should.js:61:14)

So it says they are not equal, but the diff shows no difference. And the objects look pretty equal, as expected.

I could not reproduce issue with should@4.0.4 and latest stable node. Which versions do you use?

BTW. In readme adress for new repo.

I did the following just now, to reproduce the problem. It might be a problem with mocha?

  mkdir testing
  cd testing
  npm install mocha
  npm install should
  mkdir test
  vim test/test.js

And then put the following contents of the file:

  var should = require('should');

  describe('mocha', function () {
    it('should be able to compare to equal objects', function (done) {
        var obj = { bool1: false, bool2: true };
        obj.should.equal({ bool1: false, bool2: true });
        done();
    });
  });

Then run the test by entering "mocha":

$ mocha

  mocha
    1) should be able to compare to equal objects


  0 passing (7ms)
  1 failing

  1) mocha should be able to compare to equal objects:

      AssertionError: expected { bool1: false, bool2: true } to be { bool1: false, bool2: true }
      + expected - actual

What you wrote first time and what you did are different things. First time you wrote about using .match. Second time you used .equal which is doing === (check reference equality). For your case need .eql if you want to check that it is the same object (and ignore references aka deep object comparison). .match better to use when you want to check that your object match some rules/laws.

Oh, I'm sorry. It works with match() of course. 👍