mardi 17 mai 2016

Testing if the return value of a function is equal to a specific array in chia.js

So I have a function that takes in an object literal and simply returns the keys inside an array; here is the function:

exports.isolateTheFields = function(seedCount, schemaTemplate) {
  var fields = []
  for (var field in schemaTemplate) {
    if (schemaTemplate.hasOwnProperty(field)) {
      fields.push(field);
    }
  }
  return fields;
 }

Inside my test I'm doing this:

describe('#isolateTheFields', function() {
  it('returns the keys of schemaTemplate', function() {
   isolateTheFields(10, {"f_name":"f_name","l_name":"l_name"}).should.equal(["f_name","l_name"]);
  });  
}); 

Then when I run the test I get this as an error: Screenshot Img

The arrays are visually the same and I got around the error by equating length of the array instead of content but I'm curious as to why this didn't work and what methods can used to achieve this.

Thanks in advance for any advise or comments!

Aucun commentaire:

Enregistrer un commentaire