How to send a request inside Tests?

I am deleting a parent object which also deletes a child object. After deletion, I need to send a get request and check 404 status inside test. How can I do that? I tried:

pm.test("Child category is also deleted", function(res) {
    pm.sendRequest({
        url: "url",
        method: 'GET',
        header: {
            'content-type': 'application/json',
            'Authorization': "Bearer " + pm.environment.get("accessToken"),
            'Accept': "*/*"
        }
    });
    pm.response.to.have.status(404);
});

Hey @batuarslan,

Would something like this work for you?

pm.test("Child category is also deleted", (done) => {
    pm.sendRequest({
        url:  "url", 
        method: 'GET',
        header: {
            'content-type': 'application/json',
            'Authorization': "Bearer " + pm.environment.get("accessToken"),
            'Accept': "*/*"
        },
    }, (err, res) => {
        pm.expect(res.code).to.equal(404);
        done();
    });
});

I’ve added in the done() callback so that the test won’t complete until that request has been made and returned.

3 Likes

Works perfect! Thanks (:slight_smile:

1 Like