Skip to content

Instantly share code, notes, and snippets.

@co-l
Created November 25, 2015 16:18
Show Gist options
  • Save co-l/0b598e34564631d49318 to your computer and use it in GitHub Desktop.
Save co-l/0b598e34564631d49318 to your computer and use it in GitHub Desktop.
// 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