mercredi 20 décembre 2017

Javascript: assertion with aparently equal values resulting different

I have this Javascript code:

const BaseList = {

  new: function(list) {
    this.list = list;
    return this;
  },

  sortKeys: function(key) {
    const keys = Object.keys(this.list);
    keys.push(key);
    keys.sort();
    return keys;
  }

}

module.exports = BaseList;

and I am testing sortKeys with Mocha/Assert doing this:

describe('#sortKeys', function() {
  const par = {'a': 'test_a', 'c': 'test_c'};
  const bl = BaseList.new(par);
  const sl = bl.sortKeys('b');
  assert.equal(sl,['a','b','c']);
});

It happens that my test is failing, but the failure message says:

AssertionError [ERR_ASSERTION]: [ 'a', 'b', 'c' ] == [ 'a', 'b', 'c' ]

It seems that we have two equal arrays but the assertion says they are different.

What am I missing here?

Aucun commentaire:

Enregistrer un commentaire