用摩卡和柴测试快递护照申请

时间:2017-03-31 05:11:02

标签: express mocha passport.js postman chai

我正在尝试使用mocha,chai和chai-http来测试我的应用程序。当我测试登录时,无论我尝试什么,我都无法登录。我在Postman尝试过,得到了同样的结果。

我已经看到了很多this one的答案,但我没有成功。

Passport正在做一些阻止成功登录的事情吗?我可以从浏览器登录没有问题。

1 个答案:

答案 0 :(得分:0)

我在this帖子中找到了答案,并且修补了Postman中的设置。添加内容类型x-www-form-urlencoded似乎是关键。

it('should redirect to dashboard on successful login', function(done) {
    chai.request('http://localhost:3000')
      .post('/login')
      .set('Token', 'text/plain')
      .set('content-type', 'application/x-www-form-urlencoded')
      .type('form')
      .send('grant_type=password')
      .send('username=bobby')
      .send('password=abc123')
      .end(function(err, res) {
        res.should.have.status(200);
        expect(res).to.redirectTo('http://localhost:3000/user/dashboard');
        done();
      });
  });