Created
November 25, 2015 16:18
-
-
Save co-l/0b598e34564631d49318 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm install chai express supertest | |
var fs = require('fs') | |
var expect = require('chai').expect | |
var express = require('express') | |
var supertest = require('supertest') | |
describe('file sending', function() { | |
doTest('image/png') // works | |
doTest('audio/mpeg') // fails | |
function doTest(contentType) { | |
it('works for ' + contentType, function(done) { | |
var exampleFile = 'README.md' | |
var expectedBuffer = fs.readFileSync(exampleFile) | |
var app = express() | |
app.get('/test', function(req, res) { | |
res.set('Content-Type', contentType) | |
res.download(exampleFile) | |
}) | |
supertest(app).get('/test') | |
.expect('Content-Type', contentType) | |
.expect(200) | |
.end(function(err, res) { | |
expect(Buffer.compare(expectedBuffer, res.body)).to.equal(0) | |
done() | |
}) | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment