Older `tests[]` syntax vs `pm.test()`

I recognize that tests[] is being deprecated and so I wanted to change to pm.test(). However, when I use the same function that worked before in passing and failing with test[], I get false positives with pm.test(). The example pictured below.

I am using an API that is returning an object that looks like this:

[
    {
        "id": 0,
        "heading": "",
        "title": "Title name",
        "images": {
            "phone": {
                "type": "IMAGE",
                "width": 828,
                "height": 1159
            },
            "tablet": {
                "type": "IMAGE",
                "width": 1170,
                "height": 602
            }
        },
        "menu_order": 6
    },
...

And I am testing to make sure the fields are empty.

Addtional intel:
image

macOS Mojave 10.14.5

@aredman
Hey buddy.

Have you read the documentation on test writing below?
https://learning.getpostman.com/docs/postman/scripts/test_examples/

You’re not performing an actual test/assertion in line 18 in your code example.
I’d suggest you read the official docs on tests, maybe watch a Youtube video or two.

I’d recommend these:

Amber Race has a great free tutorial on the Test Automation University website too:

2 Likes

I did read the doc’s and watched those videos. However, they all brought me back to question how are they different in use? Can you clarify more around this?

If line 18 is not a test then what is it and how do I test? All those examples never cover how to use these snippets but not dialogue on syntax.

I get false positives with pm.test()

I have the same issue.
Ive completed the basic Postman API tests courses and created my first tests, but they didnt ever fail. Even when the request failed. I`m receiving test pass even when the request body is empty.

pm.test("Verify response body data model", function () {

    const jsonData = pm.response.json();

    jsonData.data.Attribute.forEach(function(Attribute) {

        pm.expect(Attribute).to.have.property("Property");
});

});

the only way to fix this issue I found through the tests notation
var jsonData = pm.response.json();

tests['Verify response body data model'] = 

(jsonData.length > 0 &&

    jsonData.every(jsonItem => jsonItem && jsonItem.assembledDateTime)
)

Hi, for a simple null check may you should try:

const respJson = pm.response.json();
pm.test("Response null check example:", function () {
    pm.expect(respJson.shouldBeNull).to.eql(null);
    pm.expect(respJson.shouldBeNotNull).to.not.eql(null);
});