Day 08 Cannot read properties of undefindes (Find )

This is a tip for anyone doing these challenges.

The way the submit works is that its using the Postman collections API to return the collection as an JSON response.

The tests tab then has various tests checking the elements in the collection JSON.

When you have failures like this, the first thing I recommend is looking at the code for the failing test.

pm.test("Tests added correctly", () => {
    let userRequest = collection.item[0].item.find(req => { return req.name === "get random user"})
    let userTest = userRequest.event.find(event => { return event.listen === "test" })
    pm.expect(userTest.listen).equals("test")

    let femaleRequest = collection.item[0].item.find(req => { return req.name === "get female user"})
    let femaleTest = femaleRequest.event.find(event => { return event.listen === "test" })
    pm.expect(femaleTest.listen).equals("test")

    let frenchRequest = collection.item[0].item.find(req => { return req.name === "get french user"})
    let frenchTest = frenchRequest.event.find(event => { return event.listen === "test"})
    pm.expect(frenchTest.listen).equals("test")

    pass += 1
})

There are three find requests in that piece of code, and the error isn’t specifically telling you which one.

But hopefully you can see that its looking for specific request names (which will be case sensitive).

If its not obvious which one is causing the failure, then I recommend that you clone the submit request, and then add some console logs for troubleshooting purpose.

Start off by console logging the userRequest variable. Is it returning the β€œget random user” request?

Remember to delete the cloned submit request once you have resolved the issue as it might cause the badge checker to fail the submission when it counts the total number of requests.

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