https://cypress.io logo
How can I make sure my API is returning response s...
# i-need-help
s
Hi, In my current application sometime APIs take time to return the response. So how can I assert that API is returning response say within 20ms in my API tests? Here is my test for reference:
Copy code
it(${event.u.user} is NOT able to create an app by graphQL "createOneApp", () => {
      cy.createOneApp(appName, event.u.user, (response: { status: any; body: any }) => {
        expect(response.status).to.eq(403);
        expect(response.body.data).eq(null);
        assert.equal(response.body.errors[0].message, 'Forbidden resource');
      });
    });
g
In
cy.request
? Probably the simplest thing is by using https://github.com/bahmutov/cypress-time-marks and I will add a lesson to my (paid) course https://cypress.tips/courses/network-testing with such example
The simplest way is to grab the property
duration
from the object yielded by the
cy.request
s
I will check this course out and the plug-in. Thank you for your response
Appreciate your reply and hint. I was able to do this:
expect(response).to.have.property('duration').lessThan(500);