Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}))
// let's confirm the request object
.its('request.body')
// notice that we want to confirm that the "body" field is a string
// and it starts with certain prefix. Since we cannot AND conditions
// we can split checks across 2 spoks
.then(spok({
title: 'example post',
userId: 1,
body: spok.string,
}))
// cy.then(cb) yields its original subject
// thus the second .then(cb) can work with the same request
// https://on.cypress.io/then
.then(spok({
body: spok.startsWith('this is a post'),
}))
// cy.its(...) yields the property value
// so if we want to validate the response object
// we need to get the XHR object again
// by now the object exists, thus we can use cy.get()
cy.get('@post').its('response').should(spok({
headers: {
'content-type': 'application/json; charset=utf-8',
'cache-control': 'no-cache',
},
body: {
title: 'example post',
body: spok.string,
userId: 1,
// we don't know the exact id the server assigns to the new post