How to use the cy-spok.range 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
// see https://on.cypress.io/network-requests
    cy.server()
    cy.route('POST', '/posts').as('post')

    cy.get('#load').click()
    cy.contains('#output', '"title": "example post"').should('be.visible')

    // Spok https://github.com/thlorenz/spok is a mix between schema and value assertions
    // Since it supports nested objects, in a single "should()" we can verify desired
    // properties of the XHR object, its request and response nested objects.
    cy.get('@post').should(spok({
      status: 201,
      url: spok.endsWith('posts'),
      // network request takes at least 10ms
      // but should finish in less than 1 second
      duration: spok.range(10, 1000),
      statusMessage: spok.string,
      // check the request inside XHR object
      request: {
      // using special keyword "$topic" to get
      // nicer indentation in the command log
        $topic: 'request',
        body: {
          title: 'example post',
          userId: 1,
        },
      },
      response: {
        $topic: 'response',
        headers: {
          'content-type': 'application/json; charset=utf-8',
          'cache-control': 'no-cache',

cy-spok

Wrapper for spok assertion

MIT
Latest version published 1 year ago

Package Health Score

58 / 100
Full package analysis