Javascript 使用nock模拟mocha中具有特定请求头的superagent请求

Javascript 使用nock模拟mocha中具有特定请求头的superagent请求,javascript,mocking,mocha.js,superagent,nock,Javascript,Mocking,Mocha.js,Superagent,Nock,我有以下代码: 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: 'd

我有以下代码:

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来模拟请求中具有特定头的请求

我是个白痴,通过阅读更多的文档,我意识到我需要使用
.matchHeader()