Assert arrays in Protractor

夙愿已清 提交于 2019-12-07 06:58:06

问题


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?


回答1:


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:

  • Jasmine JavaScript Testing - toBe vs toEqual



回答2:


Ok, I got it working by stringifying the arrays:

arrPuv = arrPuv.toString();

arrNov = arrNov.toString();

expect(arrPuv).toBe(arrNov);



来源:https://stackoverflow.com/questions/28190181/assert-arrays-in-protractor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!