在量角器中声明数组 [英] Assert arrays in Protractor

查看:87
本文介绍了在量角器中声明数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在进行E2E测试,我的目标是比较两个阵列.我将这些数组设置为相同.问题是量角器认为它们不相同.

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.

我的代码:

expect(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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆