freeCodeCamp API Test Automation for Beginners. Issue with assignment #1

I tried searching if someone else had this issue but no luck. I’m having an issue with completing an assignment as shown in this workspace. The tests I wrote definitely worked but when I check my solution I get this error in the test suite.

image

The assignment is to write a test that checks if the API returned status code 200. Here’s what it looks like.

Anyone have an idea of what’s going on?

I love the way that course is basically cribbed from the Postman Learning Centre courses, including the “If you have any failures, review the failed test results or ask for support in the community forum”.

Anyways, if you look at the failing test. It does a few things.

pm.test("Get API status contains status 200 test", () => {
    let request = folder.item.find(req => {return req.name === "Get API status"})
    pm.expect(request.event[0].script.exec.toString(), 'check script').includes("pm.test");
    pm.expect(request.event[0].script.exec.toString(), 'check script').includes("pm.response.to.have.status");
});

The error is showing 'expected " to include ‘pm.test’".

This part is basically the tests tab for the request.

request.event[0].script.exec.toString()

I suspect the issue is that its can’t find the request name.

Do you have a request called “Get API status”. (Which will be case sensitive).

Thank you for your response. I appreciate how straightforward you were with me.

The file was named correctly and after reading through the tests I realised one of them was to make sure that’s the case anyway.

That put me on the right track though, and I was able to get the test to pass after adding the test function to the pre-request script as well.

1 Like

Thanks for reaching out for help @security-observer-72 - you did nothing wrong!

I’ve improved the tests so that this issue no longer occurs.