Day 14 of 30 Days of Postman Challenge

So ive been working on this challenge and encountered an error

this is my tests tab in the get github request

this is my pre request script in the get github request
everything was fine until i came to the submission point
could someone help me out with this?

This is the failing test.

pm.test("Scripts added correctly", () => {
    let githubRequest = collection.item[0].item.find(req => { return === "github"})

    let test = githubRequest.event.find(event => {return event.listen === "test"})
    pm.expect(test.script.exec.toString(), 'check test').includes("pm.test")
    pm.expect(test.script.exec.toString(), 'check collection variable set').includes("pm.collectionVariables.set")

    let variable = collection.variable.find(variable => { return variable.key == "repoCount"})
    pm.expect(variable.key, 'check collection variable name').equals("repoCount")
    pm.expect(parseInt(variable.value), 'check collection variable value')

    pass += 1

Can you show the tests tab for your “github” request?

Your screenshot shows the pre-request scripts instead.

That looks ok to me, the odd thing is that the failing test shows the actual result first, which should show the first line of the tests tab, but the text looks different to your test (although I’m not sure if your second screenshot is the top of your tests tab or not).

The test thinks the first line of your test tab is…

// Test that the response status code

Can you share your collection?

Or alternatively, I would recommend duplicating the submit request, and then adding some console logs for the “githubRequest” and “test” variables just after they are defined.

This should return the test tab as a string.

let test = githubRequest.event.find(event => {return event.listen === "test"})

The test is just checking that the text “pm.collectionVariables.set” exists somewhere in that string.

Thank you a lot
I found the solution


Glad its working.

Would you like to share the solution?

It might help someone else who is attempting this days challenge.

Yes sure
I actually started from square 1 again for Day 14
I can remember that one of my errors was that the repocount variable had nothing in it

pm.test(“Status code is 200 and collection variable is set”, function () {;
pm.collectionVariables.set(“repoCount”, 10);
}); This is the simple code i put for my tests tab

// Pre-request Script
// Check if the pm.response object is undefined
if (pm.response !== undefined) {
// Check if the request is successful
if ( {
// Get the response body
var responseBody = pm.response.body;

// Check if the response body is undefined
if (responseBody !== undefined) {
// Convert the response body to JSON
var jsonData = JSON.parse(responseBody);

// Get the number of repositories
var repoCount = jsonData.length;

// Save the number of repositories as a collection variable
pm.collectionVariables.set(“repoCount”, repoCount);
} else {
// Handle empty response body
} else {
pm.collectionVariables.set(“repoCount”, 0);
} else {
// Handle undefined pm.response object

And this is for my prerequisites script tab there were tiny errors like the JSON body not being recognized (i parsed it in this case), etc

1 Like

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