1

次のコードがあります。

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 を使用するにはどうすればよいですか?

4

1 に答える 1

3

私は馬鹿です。ドキュメントを読んで、使用する必要があることに気付きました.matchHeader()

于 2015-03-26T12:09:21.217 に答える