TransWikia.com

expected false to deeply equal true on postman

Stack Overflow Asked by Cristian Hernandez on December 17, 2020

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);
}

enter image description here

2 Answers

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;
}

Correct answer by chazsolo on December 17, 2020

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
    }
});

Answered by Danny Dainton on December 17, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP