5

I am working on E2E tests and my goal is to compare two arrays. I set these arrays so that they are identical. The problem is that Protractor doesn't think they are same.

My code:

expect(arrPuv).toBe(arrNov);

Console output:

Error: Expected [ '1 patro', '2. Patro', 'asdf', 'My precious', 'My precious', 'My precious', 'My precious' ] to be [ '1 patro', '2. Patro', 'asdf', 'My precious', 'My precious', 'My precious', 'My precious' ].

How can I compare them correctly?

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
Jan Kokes
  • 49
  • 1
  • 5

2 Answers2

11

This actually goes down to how are you making the expectation. toBe() would make sure both arrays are the same object. Instead, you need to compare values, use toEqual():

expect(arrPuv).toEqual(arrNov);

See also:

Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
-2

Ok, I got it working by stringifying the arrays:

arrPuv = arrPuv.toString();

arrNov = arrNov.toString();

expect(arrPuv).toBe(arrNov);

Community
  • 1
  • 1
Jan Kokes
  • 49
  • 1
  • 5