Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

65
Views
Cy.intercept query does not work with arrays

I mocking endpoint with query parameters in Cypress. But when give query field with array of field items.

 cy.intercept(
    {
      method: 'POST',
      pathname: '/api/initiate/manual',
      hostname: Cypress.env('CY_API_URL'),
      https: true,
      query: {
        orderId: '13535353453',
        items: [
          {
            id: '3853438474',
            name: 'Standard Wholesale HB Yellow Pencils',
          },
          {
            id: '2424534353453',
            name: 'natural wood dipped end 72 color',
          },
        ],
      },
    },
    {
      statusCode: 200,
    },
  ).as('mockManuelOrder');

it gives error :

CypressError

An invalid RouteMatcher was supplied to cy.intercept(). query.items must be a string or a regular expression.

how I can solve the problem ?, I need to send the query parameters as it is.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

This seems to work, although I've guessed what the URL looks like when sent over the wire (may not correspond).

Basically, I've moved the query params from the RouteMatcher into the RouteHandler and used javascript to check them.

If they match, I assign a dynamic alias and send the stub response.

cy.intercept(
{
  method: 'POST',
  pathname: '/api/initiate/manual',
  hostname: Cypress.env('CY_API_URL'),
  https: true,
},
(req) => {
  const params  = {
    "orderId": "13535353453",
    "items": [
      {"id": "3853438474", "name": "Standard Wholesale HB Yellow Pencils"},
      {"id": "2424534353453", "name": "natural wood dipped end 72 color"}
    ]
  }

  const matches = req.query.orderId === params.orderId &&
      req.query.items == JSON.stringify(params.items)

  if (matches) {
    req.alias = 'mockManuelOrder'
    req.reply({statusCode: 200})
  }
}

// trigger POST

cy.wait('@mockManuelOrder')    // passes
about 4 years ago · Juan Pablo Isaza Report

0

It should be working:

query: JSON.stringify({
    orderId: '13535353453',
    items: [
      {
        id: '3853438474',
        name: 'Standard Wholesale HB Yellow Pencils',
      },
      {
        id: '2424534353453',
        name: 'natural wood dipped end 72 color',
      },
    ],
  }),
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!