Pet*_*ppy 12 javascript mocha.js basic-authentication node.js supertest
我正在尝试为我们设置测试,以验证用户名和密码的基本身份验证阻止的路径的用户名和密码.
it('should receive a status code of 200 with login', function(done) {
request(url)
.get("/staging")
.expect(200)
.set('Authorization', 'Basic username:password')
.end(function(err, res) {
if (err) {
throw err;
}
done();
});
});
Run Code Online (Sandbox Code Playgroud)
Yve*_* M. 26
SuperTest基于SuperAgent,它提供了auth方法以方便基本身份验证:
it('should receive a status code of 200 with login', function(done) {
request(url)
.get('/staging')
.auth('the-username', 'the-password')
.expect(200, done);
});
Run Code Online (Sandbox Code Playgroud)
资料来源:http://visionmedia.github.io/superagent/#basic-authentication
PS:您可以done
直接转到任何一个.expect()
电话
归档时间: |
|
查看次数: |
9702 次 |
最近记录: |