Skip to content

[🐛 Bug]: Mocks are returning bodies with extra metadata #14390

@grant-mccarriagher

Description

@grant-mccarriagher

Have you read the Contributing Guidelines on issues?

WebdriverIO Version

9.12.4

Node.js Version

20.15.1

Mode

WDIO Testrunner

Which capabilities are you using?

What happened?

Mocks are no longer returning the bodies that are specified in the mock. Instead, they return in the format of:

{
  "type": "string",
  "value": "{'whateverYouSpecifiedAsThe': 'mock'}"
}

What is your expected behavior?

Mocks return the value specified, as is.

How to reproduce the bug.

Here's the code I'm using:

const mockResponse = {
  data: {
    someProperty: 123,
  }
};

const theMock = await browser.mock('https://some.site.com/someEndpoint', { method: 'POST' });

theMock.respond(mockResponse, {
  statusCode: 200,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-allow-methods': '*',
    'access-control-allow-headers': '*',
    'content-type': 'application/json; charset=utf-8'
  },
  fetchResponse: false
});

In the network console in the browser, I will then see the endpoint returning this:

{
    "type": "string",
    "value": "{\"data\":{\"someProperty\": 123}}"
}

I believe this may have been introduced in #14360.

Relevant log output

Not seeing anything in the log relevant here.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Is there an existing issue for this?

  • I have searched the existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bug 🐛help wantedIssues that are free to take by anyone interested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions