Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_body key instead of body in response #815

Open
3 tasks done
MartialSeron opened this issue Jan 27, 2023 · 1 comment
Open
3 tasks done

_body key instead of body in response #815

MartialSeron opened this issue Jan 27, 2023 · 1 comment
Labels

Comments

@MartialSeron
Copy link

MartialSeron commented Jan 27, 2023

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.
@MartialSeron
Copy link
Author

MartialSeron commented Jan 30, 2023

It works up to version 6.1.6, but from version 6.2.0, it doesn't work anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant