1

Taking an array such as ['hello', 'there'] and storing that in a Mongoose document with a schema such as

tags: { type: Array }

using something such as:

Something.create({ tags: ['hello', 'there']}, cb);

Then using ShouldJS to check that the document matches my supplied array I would expect this:

doc.tags.should.eql(['hello', 'there']);

But it does not. If I console.log doc tags I get:

[hello, there] 

Notice that the quotes are gone. The doc.tags is indeed an array (I can check instanceof Array) and I can also use shouldjs with

doc.tags.should.have.keys('hello');
doc.tags.should.have.keys('there');

Anyone have an idea as to why my array doesn't match anymore?

cyberwombat
  • 38,105
  • 35
  • 175
  • 251

1 Answers1

3

Your array is not a real json Array: it's a MongooseArray, with additional methods.

To make should.eql work with mongoose array, first use toObject():

doc.tags.toObject().should.eql(['hello', 'there']);
user1409932
  • 161
  • 1
  • 10