Mocha supertest 不发布数据

Mocha supertest isn't POSTing data

我的测试看起来像:

const request = require('supertest-as-promised')
const app = require('../app')

describe("Basic Authentication with JWT", () => {
  it('Should login properly', function () {
    return request(app)
      .post('/login')
      .field('name', 'myname')
      .field('password', 'password')
      .expect(200)
  });
})

在我的应用程序中,我有:

  app.post("/login", (req, res) => {
    console.log(req.body)

当我运行应用程序正常时,它可以正确获取信息。当我运行测试时,它显示为{}

什么给了?

尝试这样的事情:

 describe("Basic Authentication with JWT", () => {
      it('Should login properly', function () {
        request(app)
                .post('/login')
                .send({
                    name: "test_name",
                    password: "test_password"
                })
                .then((res) => {
                    res.statusCode.should.eql(200);
                    done();
                })
                .catch(done)
      });
    })