node.js - Expect array to be array -


writing tests , ran across error. array's seem same me, apparently not. error i'm getting. idea on fix it?

expected array [ 'a2t1511300361', 'a2t1511300362' ] array [ 'a2t1511300361', 'a2t1511300362' ]

test.js

var should = require('should'),  io = require('socket.io-client'), path = require('path'), express = require(path.resolve('./config/lib/express')), mongoose = require('mongoose'), sinon = require('sinon')     ...  client.on('printerlist', function(list){      var temparray = [];     temparray.push('a2t1511300361');     temparray.push('a2t1511300362');     console.log(temparray);      list.should.equal(temparray);   }); 

you cannot directly test array quality in manner doing. [1,2] , [1,2] may have same elements, different arrays. more formally:

[ ] !== [ ] [ ] != [ ]

you trying test deep equality. this, need check each array element. many methods in lodash, example, can this. e.g.

// uses es6 syntax const _ = require('lodash') const arr1 = [1, 2] const arr2 = [1, 2] assert.equal(_.intersection(arr1, arr2).length, arr1.length)) assert.equal(_.intersection(arr1, arr2).length, arr2.length))


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -