简体   繁体   中英

expected false to deeply equal true on postman

I am trying to write a test to confirm that "Active": true and am struggling. Apologies in advance for sloppy code. This is what I have tried and I am getting "AssertionError: expected false to deeply equal true"

Here is my code and response body I am receiving.

var jsonData = pm.response.json();
for (i of jsonData.resources) {
var found = false;
var serviceID = pm.environment.get("serviceID");
for (i of jsonData.resources) {
    if (i.ID == serviceID) {
        if (i.Active == "true") {
            found = true;
            break;
        }
    }
}
pm.expect(found).to.be.eql(true);
}

在此处输入图像描述

You are checking if i.Active == "true" but your data shows i.Active as a boolean, not a string ( true !== 'true' ).

Check for a boolean instead:

if (i.Active === true) {
  found = true;
  break;
}

Something like this will work for what you're trying to do:

let jsonData = pm.response.json(),
     serviceID = pm.environment.get("serviceID");

_.each(jsonData.resources, (item) => {
    if (item.ID === serviceID) {
        pm.expect(item.Active).to.be.true
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM