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

@shopify/cypress-graphql

Package Overview
Dependencies
Maintainers
18
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shopify/cypress-graphql

Cypress commands for stubbing, intercepting and testing graphql endpoints

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
18
Created
Source

@shopify/cypress-graphql

Build Status License: MIT npm version npm bundle size (minified + gzip)

Cypress commands for intercepting and testing graphql endpoints.

Installation

Install this package w/ npm or yarn

npm install --dev @shopify/cypress-graphql
yarn add --dev @shopify/cypress-graphql

Then in your cypress/support/index files, import the entire package to register these commands.

import '@shopify/cypress-graphql';

Typescript types are automatically included, so no further action is required.

Usage

cy.interceptGql

This command sets up spies and stubs for a graphql endpoint, similar to cypress route intercepts. This registers a top-level route alias called GraphQL. Optionally, but definitely encouraged is providing an array of known operations, which will then be registered as sub-operations with their own aliases.

Intercept any request
cy.interceptGql('**/graphql')                         // register route intercepts
cy.get('button[type="submit"]').click()               // make the UI send a request
cy.wait('@GraphQL').its('status').should('eq', 200)   // test the response
Intercept a specific operation
cy.interceptGql('**/graphql', ['UserQuery'])          // register route intercepts
cy.get('button[type="submit"]').click()               // make the UI send a request
cy.wait('@UserQuery').its('status').should('eq', 200) // test the response
Stub a specific operation
cy.interceptGql('**/graphql', [
  ['UserQuery', { statusCode: 400, body: { data: null, errors: ['fake err']  } }]
])                                                    // provide a fake error
cy.get('button[type="submit"]').click()               // make the UI send a request
cy.wait('@UserQuery').its('status').should('eq', 400) // test the response

FAQs

Package last updated on 03 Oct 2022

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