Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cypress-should

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cypress-should

Supercool assertion library for Cypress

  • 0.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
416
decreased by-8.77%
Maintainers
0
Weekly downloads
 
Created
Source

Stand With Ukraine

cypress-should


tests NPM version monthly downloads downloads all time commits MIT licensed

Supercool assertion library for Cypress to verify API responses

Install

npm install --save-dev cypress-should

Usage

In your cypress/support/index.js file, add the following:

require('cypress-should');

or if you are using TypeScript:

import 'cypress-should';

Then in your tests, you can use the should command with custom assertions to verify the response:

cy.request('/api/users')
  .should('have.status', 200)
  .and('have.statusMessage', 'OK')
  .and('have.contentType', 'application/json')
  .and('have.body', { name: 'John Doe' });

or

cy.request('/api/users').should((response) => {
  expect(response).to.have.status(200);
  expect(response).to.have.statusMessage('OK');
  expect(response).to.haveContentType('application/json');
  expect(response).to.have.body({ name: 'John Doe' });
});

API

have.status - Asserts the response status code

cy.request('/api/users').should('have.status', 200)

have.statusMessage - Asserts the response status message

cy.request('/api/users').should('have.statusMessage', 'OK')

have.contentType - Asserts the response content type

cy.request('/api/users').should('have.contentType', 'application/json')

have.body - Asserts the response body

cy.request('/api/users').should('have.body', { name: 'John Doe' })

have.header - Asserts the response header

cy.request('/api/users').should('have.header', 'x-powered-by', 'Express')

have.cookie - Asserts the response cookie

cy.request('/profile').should('have.cookie', 'session_id')

containBody - Asserts the response body contains the given value

cy.request('/api/users').should('containBody', { name: 'John Doe' });

haveText - Asserts the response body is equal to the given text

cy.request('/home').should('haveText', 'Hello World!');

containText - Asserts the response body contains the given text

cy.request('/home').should('containText', 'World!');

be.json - Asserts the response body is a valid JSON

cy.request('/api/users').should('be.json');

be.html - Asserts the response body is a valid HTML

cy.request('/home').should('be.html');

be.text - Asserts the response body is a valid text

cy.request('/home').should('be.text');

be.xml - Asserts the response body is a valid XML

cy.request('/home').should('be.xml');

License

MIT

Author

Yevhen Laichenkov elaichenkov@gmail.com

Keywords

FAQs

Package last updated on 21 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc