使用 cypress 我正在拦截 API 调用,并想了解它花费了多少响应时间
cy.intercept("PATCH", "https://api.website.com/b2b2/**").as("myAPP")
cy.wait("@myAPP").then(({ request, response }) => {
expect(response.duration).to.be.lessThan(2000)// => expected undefined to be a number or a date
expect(response.statusCode).to.equal(200)
})
在 JavaScript 中,您可以使用
performance
API 来测量 API 调用的速度。
例如:
const start = performance.now();
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => {
const end = performance.now();
const responseTime = end - start;
console.log(`Response time: ${responseTime} milliseconds`);
});