cy.interceptWs('/ws', (income, outcome) => {
if (income) {
// TODO
}
if (outcome) {
// TODO
}
return {income: income, outcome: outcome}
});
// cypress.json
{
"env": {
"cypressWsProxy": {
"serverPort": "4321",
"targetUrl": "wss://gas-price-api-staging.1inch.io/ws"
}
}
}
Install package:
# for npm
npm install cypress-ws-intercept
# for yarn
yarn add cypress-ws-intercept
required: load this module from the support file
// cypress/support/commands.js
import 'cypress-ws-intercept/dist/commands';
required: load this module from the plugin file
// cypress/plugins/index.js
module.exports = (on, config) => {
require('cypress-ws-intercept/dist/plugin')(on, config);
// make sure to return the config object
// as it might have been modified by the plugin
return config
}
optional: add TypeScript types
{
"compilerOptions": {
"types": ["cypress", "cypress-ws-intercept"]
}
}