我有以下代码:
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 模拟请求中具有某些标头的请求?