0

I'm trying to mock a rest call in Cypress. This rest call should return a map as response, e.g.:

cy.intercept('POST', 'path', new Map([['a', 'abc']])

The problem is that this will return an empty object instead of the expected map.

To make it work, I have to write the map like:

 cy.intercept('POST', 'path', {a: 'abc'})

Note: I'm using TS and, inside its configuration file, I have target: es5 and "lib": ["esnext"]

Little Monkey
  • 5,395
  • 14
  • 45
  • 83

1 Answers1

2

HTTP POST does not support the Javascript Map object as a response, but you can convert on the fly in your test.

Please see Convert Map to JavaScript object, in your test

cy.intercept('POST', 'path', Object.fromEntries(new Map([['a', 'abc']]))
Jhaidel
  • 149
  • 6