断言数组包括带有Chai的数组 [英] Assert array includes array with Chai

查看:222
本文介绍了断言数组包括带有Chai的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试评估从2D数组的表(table.getData())返回的数据是否包含另一个数组。

I am trying evaluate whether data returned from a table (table.getData()) which is a 2D array contains another array.

在控制台中,期望的数据出现在从table.getData()调用返回的2D数组中,但是断言失败。

In the console the expected data appears in the 2D array returned from the table.getData() call but the assertion fails.

this.Then(/^I see my account balances as follows:$/, function (tableData, done) {
        var balanceAggregationPage = new BalanceAggregationPage(this.app.pagesContainer),
            table = balanceAggregationPage.getAccountsTable();

        var rows = tableData.getRows();
        rows.shift();

        var actualBalances = [];
        rows.syncForEach(function (item) {
            var row = item.raw();
            row[7] = moment(parseInt(row[7], 10)).format('DD MMM YYYY hh:mm');

            actualBalances.push(row);
        });
        exp(table.getData()).to.eventually.include(actualBalances).notify(done);
    });

有人可以帮忙吗?
谢谢

Can anyone help out? Thanks

推荐答案

您可以将 include members()


目标是集合的超集,或者目标和集合具有相同的严格相等(===)成员。或者,如果设置了deep标志,则比较set成员的深度相等性。

Asserts that the target is a superset of set, or that the target and set have the same strictly-equal (===) members. Alternately, if the deep flag is set, set members are compared for deep equality.

您的断言变为:

exp(table.getData()).to.eventually.deep.include.members([actualBalances]);

使用 deep 标志来确保chai将比较两个数组的深层内容。

Use the deep flag to ensure that chai will will compare the deep content of both arrays.

此外,这仅在数组内部的顺序相同时才有效。您可能要对它们进行排序。

Also, this will work only if the order inside the arrays is the same. You may want to sort them.

我写了一个小此处的示例即可满足您的需求。它使用应该界面代替期望,但这没关系。

I wrote a small example here that does what you want. It uses the 'should' interface instead of 'expect', but this does not matter.

这篇关于断言数组包括带有Chai的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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