Mocha supertest不是POSTing数据

时间:2017-11-30 15:36:56

标签: node.js express mocha supertest

我的测试看起来像:

parseParens "()" --> EmptyList
parseParens "(())" --> Cons EmptyList EmptyList
parseParens "((()()))" --> Cons (Cons EmptyList (Cons EmptyList EmptyList)) EmptyList

在我的应用中,我有:

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)

是什么给出了?

1 个答案:

答案 0 :(得分:2)

尝试类似的东西:

 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)
      });
    })