为什么在以下赛普拉斯测试中响应未返回ID

时间:2018-12-14 02:18:41

标签: javascript cypress

为什么在下面的赛普拉斯测试中response不返回idconsole.log()打印为'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);
   })
})

0 个答案:

没有答案