Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postman AssertionError expected: 'value' to equal value

ISSUE: In Postman I'm running a POST request and trying to assert what I receive in my response body to what is being passed via a CSV file.

The CSV file contains three columns: employee_name, employee_salary, and employee_age. All are set as general for formatting (the default).

The assert works fine for employee_name but when I try to do this for employee_age and employee_salary I get an error like this: AssertionError: expected '35' to equal 35

Here is the API I'm using.

WHAT I'VE TRIED: I've tried setting the format of the age and salary cells in the CSV file to text and to number to no avail.

CODE:

    var jsonData = pm.response.json();

    pm.test("Verify name", function() {
        pm.expect(jsonData.data.name).to.equal(pm.iterationData.get("employee_name"));
    });

    pm.test("Verify age", function() {
        pm.expect(jsonData.data.age).to.equal(pm.iterationData.get("employee_age"));
    });

    pm.test("Verify salary", function() {
        pm.expect(jsonData.data.salary).to.equal(pm.iterationData.get("employee_salary"));
    });

Thanks for any help!

Best, Jason

like image 794
JBird1977 Avatar asked Jul 27 '26 19:07

JBird1977


1 Answers

It's trying the match a string with an Integer so you could wrap the values from the data file with parseInt().

For example, the age would be like this:

pm.expect(jsonData.data.age).to.equal(parseInt(pm.iterationData.get("employee_age")))

like image 53
Danny Dainton Avatar answered Jul 29 '26 08:07

Danny Dainton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!