How to use the cy-spok.startsWith function in cy-spok

To help you get started, we’ve selected a few cy-spok examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cypress-io / cypress-example-recipes / examples / server-communication__xhr-assertions / cypress / integration / spok-spec.js View on Github external
}))
    // 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

cy-spok

Wrapper for spok assertion

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis