Tests "pass" after a failed assertion

Looks like this started happening after I upgraded postman, and tests became “post-response scripts”.
I have this as a post-response script:

pm.test("foo", () => { pm.expect(1).to.eql(0); console.log("foo"); })

It aborts (log is never printed), but the test is marked as passed

Hey @dimatkach :wave:

Welcome to the Postman community :postman:

Nothing in terms of functionality has change there, only the label and the location of the script.

What is it that you’re trying to do? What’s the actual scenario you’re running here and not the mock test that you have created.

In order to help you, it would be easier for us to have the full picture and the context of your workflow :pray:

It looks like literally nothing else is going on here in terms of a “scenario” (I have spent half of my day to prove it to myself).
Here is the whole “collection” I just created to demonstrate it. I just hit “Send”, it runs the request, and the script, and says everything looks good.
The log line is never printed (nothing at all in console except for the actual request), but the dot next to “Scripts” in the ui is green.

{
  "info": {
    "_postman_id": "5a99cd97-a002-424f-afa1-402e14af547d",
    "name": "bug",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
    "_exporter_id": "31967039"
  },
  "item": [
    {
      "name": "New Request",
      "event": [
        {
          "listen": "test",
          "script": {
            "exec": [
              "pm.test(\"foo\", function() {  pm.expect(1).to.eql(0); })"
            ],
            "type": "text/javascript",
            "packages": {}
          }
        },
        {
          "listen": "prerequest",
          "script": {
            "exec": [],
            "type": "text/javascript"
          }
        }
      ],
      "request": {
        "method": "GET",
        "header": [],
        "url": {
          "raw": "https://google.com",
          "protocol": "https",
          "host": [
            "google",
            "com"
          ]
        }
      },
      "response": []
    }
  ]
}

I’ve copied that test verbatim and it appears to work for me.

image

image

If the test fails, then the console log command should not execute.

Are you saying you get a “green” pass in the “Test Results” tab?

If I change the assertion to pm.expect(1).to.eql(1) then the console log is triggered as expected.

image

Oh … I wasn’t looking at the Test Results tab. It does it did mark it as failed there correctly. I was expecting the dot next to “Scripts” label to turn red too – that’s what confused me. It used to do that when it was “Tests”

It previously didn’t go red - The dot on the Tests section would have still been green:
Screenshot 2024-06-12 at 16.03.31

If you had a script error, it would have turned red:

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.