0

我开始学习 FrisbyJS 并尝试创建一些断言。

我得到一个看起来像这样的 json

[
    {
        "articles": [
            {
                "article": "123-123002",
                "updated": "2016-10-20T14:57:25",
                "sourced balance": [],
                "balance": "50.00"
            },
            {
                "article": "100-123001",
                "updated": "2016-10-20T14:41:36",
                "sourced balance": [],
                "balance": "10.00"
            }
        ],
        "DistrictID": [],
        "WarehouseID": "SebastiansWarehouse",
        "SourceID": "1234",
        "City": "Stockholm",
        "WarehouseName": "Sebastians Warehouse",
        "WarehouseType": "STORE"
    }
]

我想:1.计算文章对象的数量2.验证文章数组中的数字X是否有一个值为“123-123002”的变量

我怎样才能在 Frisby 做到这一点?

我目前的代码是:

var frisby = require('frisby');

frisby.create('Mekonomen RIF1')
  .get('https://10.254.8.67:9443/INTERSHOP/rest/WFS/Mekonomen-MekB2BSE-Site/-/availability/sources/1234/warehouses/SebastiansWarehouse/products/',{ strictSSL: false})
  .expectStatus(200)
.expectHeaderContains('content-type', 'application/json')
.expectJSON('?',{
        articles: [],
        DistrictID: [],
        WarehouseID: "SebastiansWarehouse",
        SourceID: '1234',
        City: "Stockholm",
        WarehouseName: "Sebastians Warehouse",
        WarehouseType: "STORE"
    }
)
.expectJSON('?.articles',{
        articles: [],
        DistrictID: [],
        WarehouseID: "SebastiansWarehouse",
        SourceID: '1234',
        City: "Stockholm",
        WarehouseName: "Sebastians Warehouse",
        WarehouseType: "STORE"
    }
)
.expectMaxResponseTime(500)
.toss();
4

1 回答 1

1

你可以包括

.afterJSON(json){ //json.articles can be asserted here //some more assertion on the response }

它将解析响应并将其作为参数发送,该参数可以使用简单的 javascript 条件、语句、循环等进行断言。

于 2017-05-03T20:22:12.627 回答