Skip to content

_body key instead of body in response #815

Open
@mrtl-srn

Description

@mrtl-srn

Describe the bug

Node.js version: >= 14

OS version: Docker devcontainer with vscode image

Description:

There is a _body key instead of body in response.
I don't know if it's an expected behavior due to recent changes but it's a breaking change for all my tests

Actual behavior

// ./app.js

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.json({
    ok: true,
  })
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
});

module.exports = app;
// ./tests/app.test.js

const supertest = require('supertest');
const { expect } = require('chai');
const app = require('../app.js');


const server = supertest.agent(app);

describe("Tests", () => {
  it('should return a JSON object', async () => {
    const response = await server.get('/').expect(200);

    console.log({ response });

    expect(response).to.haveOwnProperty('body');
  });
});

Result

  1) Tests
       should return a JSON object:
     AssertionError: expected { Object (_events, _eventsCount, ...) } to have own property 'body'
      at Context.<anonymous> (tests/app.test.js:14:25)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

In the response object there is no "body", only a "_body"

image

Expected behavior

"body" should be present and test should pass.

Code to reproduce

Here is a replit example : https://replit.com/@MartialSeron/RowdyTenseLocations#tests/app.test.js
You just have to run npm test in the shell

Checklist

  • I have searched through GitHub issues for similar issues.
  • I have completely read through the README and documentation.
  • I have tested my code with the latest version of Node.js and this package and confirmed it is still not working.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions