Why the response
doesn't return id
in the below cypress test, console.log()
printing as 'undefined'
describe('Hello', function() {
it.only('Hello', function() {
const getId = function() {
cy.request('GET', 'https://jsonplaceholder.typicode.com/posts/42')
.then((response) => {
//response.body is automatically serialized into JSON
return response.body.id
})
}
const user_Id = getId();
console.log("This is my request"+user_Id);
})
})