Skip to content
Latchkey

Newman sandbox "There was an error in evaluating the test script" in CI

Newman ran a pre-request or test script inside its sandbox and the JavaScript threw. A ReferenceError or reading a property of undefined stops the script, and Newman reports the sandbox evaluation error for that request.

What this error means

Newman prints "There was an error in evaluating the test script" or a ReferenceError under a request, and the assertions in that script do not run.

newman
  POST Create order
    There was an error in evaluating the test script:
    ReferenceError: pmResponse is not defined
      inside "Create order"

Common causes

A typo or undefined variable in the script

The script references a name that does not exist (a typo for pm.response, or a variable set on a prior request that did not run), throwing a ReferenceError.

Reading a property before the response parsed

The script calls pm.response.json() on a non-JSON body or reads a field of an undefined object, throwing a TypeError inside the sandbox.

How to fix it

Fix the script reference and guard undefined

  1. Read the error to find the exact undefined name or property.
  2. Correct the reference (use pm.response, pm.environment.get(...)).
  3. Guard optional fields before reading them so the sandbox does not throw.
Postman test script
pm.test("has order id", function () {
  const body = pm.response.json();
  pm.expect(body).to.have.property("id");
});

Run one request in isolation to debug

Use a folder or a single request with --verbose to see the failing script in isolation before the full run.

Terminal
newman run collection.json --folder "Create order" --verbose

How to prevent it

  • Reference Postman sandbox objects by their exact names (pm.response, pm.environment).
  • Guard optional response fields before reading them.
  • Keep scripts small and test them with a single-folder run.

Frequently asked questions

What causes ""error in evaluating the test script""?
The script references a name that does not exist (a typo for pm.response, or a variable set on a prior request that did not run), throwing a ReferenceError.
How do I fix "error in evaluating the test script"?
Fix the script reference and guard undefined

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card