【发布时间】:2015-03-25 22:12:31
【问题描述】:
我有以下代码:
var request = require('superagent');
var nock = require('nock')
var scope = nock('http://localhost:80', {
reqheaders: {
'Content-Type': 'text/html'
}
});
scope.post('/api/test', {
test: 'data'
})
.reply(200, {
test: 'data2'
});
describe.only('test', function() {
it('should fail', function(done) {
request
.post('/api/test')
.set('Content-Type', 'application/json')
.send({test: 'data'})
.end(function(response) {
expect(response.body).to.deep.equal({test: 'data2'});
done();
});
});
});
现在,除非我无法理解 reqheaders,否则我预计此测试会失败,因为我将请求标头设置为 application/json 而不是 text/html,但测试通过了。
我想念reqheaders 的用法吗?如何使用 nock 模拟请求中具有某些标头的请求?
【问题讨论】:
标签: javascript mocking mocha.js superagent nock