Hello everyone, pls help me i m facing issue at Test result showing failure when i send a request to see Wht books to checkout?

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.

Here’s an outline with best practices for making your inquiry.

My question:

Details (like screenshots):

How I found the problem:

I’ve already tried:
Capture

Your screenshot is not visible put your response body and what assertion you have used then I m able to help you.

i have used this assertion , below is the failure i m getting in test Results .

pls help

Hi @yashikag-2802 , can you please paste your test script as well. Looks like in your test script you are trying to validate it otherwise.

pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});

pm.test(“Correct method is used in request”, function () {
const cond = pm.request.method === “GET”;
pm.expect(cond).to.eql(true);
});

pm.test(“Correct path is used in request”, function () {
pm.expect(pm.request.url.path[0]).to.match(/^books$/);
});

const body = pm.response.json()

pm.test(“Response is an array”, function () {
const cond = Array.isArray(body)
pm.expect(cond).to.eql(true);
});

pm.test(“Only books that are not currently checked out are returned”, function () {
const cond = body.every(book => !book.checkedOut)
pm.expect(cond).to.eql(true);
});

Hey @yashikag-2802 ,

So you see the condition you are trying to test is

!book.checkedOut
this means that whaver you will get in your response negative of that so for current resposne which is true, cond becomes false and in next statement you are expecting it to be true,

what you should do is const cond = body.every(book => book.checkedOut) this would solve out your problem.

Hope this helps.

Ohh Got it

Thanks a lot

Hi,
Could you please help me? I faced same issue.