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"})
console.log(test.script.exec.toString();
The test is just checking that the text “pm.collectionVariables.set” exists somewhere in that string.
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.response.to.have.status(200);
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 (pm.response.to.be.ok) {
// 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