在量角器中断言数组 [英] Assert arrays in Protractor
问题描述
我正在进行 E2E 测试,我的目标是比较两个数组.我设置这些数组,使它们是相同的.问题是 Protractor 认为它们不一样.
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.
我的代码:
期望(arrPuv).toBe(arrNov);
expect(arrPuv).toBe(arrNov);
控制台输出:
错误:预期 ['1 patro', '2.Patro','asdf','我的宝贝','我的宝贝','我的宝贝','我的宝贝'] 是 ['1 patro','2.Patro','asdf','我的宝贝','我的宝贝','我的宝贝','我的宝贝'].
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' ].
如何正确比较它们?
推荐答案
这实际上取决于您如何做出期望.toBe()
将确保两个数组是同一个对象.相反,您需要比较值,使用toEqual()
:
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);
另见:
这篇关于在量角器中断言数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!