Express 与摩卡和柴一起测试快速护照申请
我正在尝试用mocha、chai和chai http测试我的应用程序。当我测试登录时,无论我尝试什么,我似乎都无法登录。我试过《邮递员》也得到了同样的结果 我已经看到了许多类似的答案,但我没有成功 Passport是否正在阻止成功登录?我可以毫无问题地从浏览器登录 我在《邮报》和《邮差》的设置中找到了答案。添加内容类型Express 与摩卡和柴一起测试快速护照申请,express,mocha.js,passport.js,postman,chai,Express,Mocha.js,Passport.js,Postman,Chai,我正在尝试用mocha、chai和chai http测试我的应用程序。当我测试登录时,无论我尝试什么,我似乎都无法登录。我试过《邮递员》也得到了同样的结果 我已经看到了许多类似的答案,但我没有成功 Passport是否正在阻止成功登录?我可以毫无问题地从浏览器登录 我在《邮报》和《邮差》的设置中找到了答案。添加内容类型x-www-form-urlencoded似乎是关键 it('should redirect to dashboard on successful login', function
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();
});
});
我在《邮报》和《邮差》的设置中找到了答案。添加内容类型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();
});
});