Troubleshoot common test errors

When you encounter errors or unexpected behavior in your post-response scripts, the Postman Console can help you to identify the source.

Use the Postman Console logs

By combining console.log(), console.info(), console.warn(), and console.error() debug statements with your test assertions, you can examine the content of the HTTP requests and responses, and Postman data items such as variables. You can also use the console.clear() method to clear information from the console. Select Console icon Console from the Postman footer to open it.

Console info

Log the value of a variable or response property:

console.log(pm.collectionVariables.get("name"));
console.log(pm.response.json().name);

Log the type of variable or response property:

console.log(typeof pm.response.json().id);

Use Console logs to mark code execution, sometimes known as “trace statements”:

if (pm.response.json().id) {
  console.log("id was found!");
  // do something
} else {
  console.log("no id ...");
  //do something else
}

Assertion deep equality error

You might encounter the AssertionError: expected <value> to deeply equal '<value>' error. For example, this would arise with the following code:

pm.expect(1).to.eql("1");

This happens because the test is comparing a number to a string value. The test will only return true if both the type and value are equal.

Variable not defined error

You might encounter the ReferenceError: <variable> is not defined error. This typically happens when you’re attempting to reference a variable that hasn’t been declared or is outside the scope of your test code.

In the following example, a JSON object is the value of a variable in the first test. The second test is attempting to reference the variable, but it can’t because the variable is outside the scope of the second test’s code.

/* Response has the following structure:
{
  "name": "John",
  "age": 29
},
*/
pm.test("Test 1", () => {
  const jsonData = pm.response.json();
  pm.expect(jsonData.name).to.eql("John");
});

pm.test("Test 2", () => {
  pm.expect(jsonData.age).to.eql(29); // ReferenceError: jsonData is not defined
});

Make sure variables are available at the global scope if test functions needs to reference it. In the previous example, moving const jsonData = pm.response.json(); before the first pm.test would make it available to both test functions.

Assertion undefined error

You might encounter the AssertionError: expected undefined to deeply equal <value> error. Typically this happens when you are referring to a property that doesn’t exist or is out of scope.

const jsonData = pm.response.json();
pm.expect(jsonData.name).to.eql("John");

In this example, if you get the error AssertionError: expected undefined to deeply equal 'John', this indicates that the name property isn’t defined in the jsonData object.

Test not failing

There may be occasions where you expect a test to fail, and it doesn’t. Make sure your test code is syntactically correct, then resend your request.

In the following example, the test is expected to fail because true doesn’t equal false. The test actually passes because the pm.test function isn’t correctly defined. The pm.test function is missing the first parameter, which is a text string that displays in the test result output. You can learn more about defining tests using the pm.test function.

pm.test( function () {
    pm.expect(true).to.eql(false);
});

Last modified: 2025/06/12