Complete the code to assert the response status is 200.
cy.request('/api/data').then((response) => { expect(response.status).to.equal([1]) })
The HTTP status code 200 means the request was successful. We assert that the response status equals 200.
Complete the code to assert the response body has a property 'name'.
cy.request('/api/user').then((response) => { expect(response.body).to.have.[1]('name') })
length which checks array length, not object keys.include which checks for substring or array inclusion.The property assertion checks if the object has a specific key. Here, we check if response.body has a 'name' property.
Fix the error in the assertion to check the response body equals the expected object.
const expected = { id: 1, name: 'Alice' };
cy.request('/api/user/1').then((response) => {
expect(response.body).to.[1](expected)
})equal which compares object references, not content.eql which is an alias but less explicit.To compare objects deeply in Cypress, use deep.equal. It checks all nested properties for equality.
Fill both blanks to assert the response body array has length 3 and includes an object with id 2.
cy.request('/api/items').then((response) => { expect(response.body).to.have.length[1]; expect(response.body).to.deep.include([2]); })
length(2) which is the wrong size.deep.include.The length(3) assertion checks the array size. The deep.include checks if the array contains an object with id: 2.
Fill all three blanks to assert the response body has a nested property 'user.email' equal to 'test@example.com'.
cy.request('/api/profile').then((response) => { expect(response.body).to.have.nested.[1]('[2]').that.equals([3]) })
length instead of property.Use have.nested.property('user.email') to check nested keys. Then assert it equals the expected email string.