Translate old test assertion to pm.test

Hey,

I’m working on rewriting all the tests of all the requests but after 2 hours of searching the Internet, I can’t find a way to rewrite this test:

tests["Name not null"] = response.name !== null && response.name !== ""

If anyone has an idea to help me, I’ll be grateful.

Laurre

Hey @laureline.gagnon,

Welcome and thank you for posting your question :star:

If I understand what you’re trying to achieve, would this work:

pm.test("Name not null", () => {
    pm.expect(response.name).to.not.be.null
    pm.expect(response.name).to.not.be.empty
}) 

I don’t really know the full context behind the question so this is only based on the limited information I have, happy to edit the response if this doesn’t work for you.

Adding this link for reference:

Thanks !
That’s exactly what I want to do.
Is there a list of all possible functions/commands following an expect?
Because I didn’t find its possibilities during my research.

You’ll find all of the chai expect functions in the link that I provided in the answer :slight_smile:

You can also find more Postman Tests information here:

https://learning.getpostman.com/docs/postman/scripts/test_scripts/#writing-postman-tests

https://learning.getpostman.com/docs/postman/scripts/test_examples/

And more test related goodness covered in this documentation with the added bonus of using the ‘Run in Postman’ button, at the top of the page, to import the collection into your own Postman instance. :slight_smile:

Thanks for your help :slight_smile:

1 Like