と を使用してアプリケーションをビルドしていkoa
ますkoa-router
。supertest
I face a problem でルートをテストするとき、そのcontent-type
応答ヘッダーは常にapplication/json; charset=utf-8
.
const app = koa();
router
.get('/img', function *(next) {
this.type = 'image/png';
// this.set('Content-Type', 'image/png');
// this.set('content-type', 'image/png');
this.body = renderImage();
});
app
.use(router.routes())
.use(router.allowedMethods());
describe('Routes', () => {
it('should handle /tiles/*/*/*/* requests', (done) => {
request(http.createServer(app.callback()))
.get('/img')
.expect(200)
.expect('Content-Type', 'image/png')
.end(function (err, res) {
console.log(res.res.headers);
if (err) return done(err);
expect(renderImage).to.be.called;
done();
});
});
テストが失敗する方法:
エラー: "image/png" の "Content-Type" が予期されていましたが、Test._assertFunction で Test._assertHeader (node_modules/supertest/lib/test.js:215:12) で "application/json; charset=utf-8" を取得しました(node_modules/supertest/lib/test.js:247:11) で Test.assert (node_modules/supertest/lib/test.js:148:18) で Server.assert (node_modules/supertest/lib/test.js:127) :12) emitCloseNT (net.js:1525:8) で
経由でログに記録されるものconsole.log(res.res.headers)
:
{ 'content-type': 'application/json; charset=utf-8',
'content-length': '2',
date: 'Wed, 09 Mar 2016 10:15:37 GMT',
connection: 'close' }
それでも、ブラウザから提供されたルートにリクエストを行うと、content-type
ヘッダーが正しく変更されます。
Connection:keep-alive
Content-Length:334
Content-Type:image/png
Date:Wed, 09 Mar 2016 10:15:01 GMT
どちらthis.set('Content-Type', 'image/png');
も this.set('content-type', 'image/png');
状況を変えません。
バグですか?誰かが同じ問題に直面しましたか?