柴测试数组相等不能按预期工作 [英] chai test array equality doesn't work as expected

查看:64
本文介绍了柴测试数组相等不能按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么以下操作失败?

expect([0,0]).to.equal([0,0]);

什么是正确的测试方法?

解决方案

对于期望.equal将比较对象而不是它们的数据,在您的情况下,它是两个不同的数组.

使用.eql可以深度比较值.查看此链接.
或者,您可以使用.deep.equal来模拟与.eql相同的内容.
或者,您可能需要检查 .members.

对于声明,您可以使用.deepEqual链接.

Why does the following fail?

expect([0,0]).to.equal([0,0]);

and what is the right way to test that?

解决方案

For expect, .equal will compare objects rather than their data, and in your case it is two different arrays.

Use .eql in order to deeply compare values. Check out this link.
Or you could use .deep.equal in order to simulate same as .eql.
Or in your case you might want to check .members.

For asserts you can use .deepEqual, link.

这篇关于柴测试数组相等不能按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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