Thi*_*its 4 mocking mocha.js superagent nock
我不能为我的生活得到一个简单的superagent邮政请求工作.这是我的superagent和nock配置.
SuperAgent的:
request
.post('https://test.com/api/login')
.send({
email: 'test@test.com',
password: 'testpassword'
})
.end((err, res) => {
if (err) {
console.log(err);
}
});
Run Code Online (Sandbox Code Playgroud)
箭扣:
nock('https://test.com')
.post('/api/login')
.send({
email: 'test@test.com',
password: 'testpassword'
})
.reply(200, {
id: 1,
token: 'abc'
});
Run Code Online (Sandbox Code Playgroud)
我从nock收到以下错误:
{[错误:诺克:否匹配于请求POST https://test.com/api/login { "电子邮件": "test@test.com", "密码": "testpassword"}]状态:404,的StatusCode: 404,响应:undefined}
另一个奇怪的方面是我的superagent响应处理程序中记录了此错误.所以我知道这个电话正在制作和截获.
Thi*_*its 12
好的 - 想通了.在深入研究文档之后,我找到了.log函数.我像这样链接了我的nock配置
nock('https://test.com')
.log(console.log)...
Run Code Online (Sandbox Code Playgroud)
事实证明请求主体不匹配.
| 归档时间: |
|
| 查看次数: |
2728 次 |
| 最近记录: |