次のコードがあります。
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/jsontext/html
の使用を理解していreqheadersませんか? リクエストに特定のヘッダーを持つリクエストをモックするために nock を使用するにはどうすればよいですか?