tests: improve res.download tests
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parent 63ab255 · Browse files · 1 file·+26 added−28 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+26 added−28 removed
- tests:+26 added−28 removed
Provenance
- Commit
ca480d7- Tree
2b9b742- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent
63ab255
1 file changed+26 added−28 removed
modified:test/res.download.js+26 added-28 removed
12342345678928 unmodified lines383940414142424344454546474849505152525354535455565758606159606162636465666768697172737071727374757980767782787984858680818283848586928788899091929399949596979899100101102107108109110111112103104105106107108109110111112113
var express = require('../') , request = require('supertest') , assert = require('assert');var after = require('after');var assert = require('assert');var express = require('..');var request = require('supertest');
describe('res', function(){ describe('.download(path)', function(){ it('should transfer as an attachment', function(done){28 unmodified lines })
describe('.download(path, fn)', function(){ it('should invoke the callback', function(done){ var app = express() , calls = 0; var app = express(); var cb = after(2, done);
app.use(function(req, res){ res.download('test/fixtures/user.html', done); res.download('test/fixtures/user.html', cb); });
request(app) .get('/') .expect('Content-Type', 'text/html; charset=UTF-8') .expect('Content-Disposition', 'attachment; filename="user.html"') .expect(200, function(err){ assert.ifError(err) }) .expect(200, cb); }) })
describe('.download(path, filename, fn)', function(){ it('should invoke the callback', function(done){ var app = express() , calls = 0; var app = express(); var cb = after(2, done);
app.use(function(req, res){ res.download('test/fixtures/user.html', 'document', done); });
request(app) .get('/') .expect('Content-Type', 'text/html; charset=UTF-8') .expect('Content-Disposition', 'attachment; filename="document"') .expect(200, function(err){ assert.ifError(err) }) .expect(200, cb); }) })
describe('on failure', function(){ it('should invoke the callback', function(done){ var app = express() , calls = 0; var app = express();
app.use(function(req, res){ app.use(function (req, res, next) { res.download('test/fixtures/foobar.html', function(err){ assert(404 == err.status); assert('ENOENT' == err.code); done(); if (!err) return next(new Error('expected error')); res.send('got ' + err.status + ' ' + err.code); }); });
request(app) .get('/') .end(function(){}); .expect(200, 'got 404 ENOENT', done); })
it('should remove Content-Disposition', function(done){ var app = express() , calls = 0;
app.use(function(req, res){ app.use(function (req, res, next) { res.download('test/fixtures/foobar.html', function(err){ if (!err) return next(new Error('expected error')); res.end('failed'); }); });
request(app) .get('/') .expect('failed') .end(function(err, res){ if (err) return done(err); res.header.should.not.have.property('content-disposition'); done(); }); .expect(shouldNotHaveHeader('Content-Disposition')) .expect(200, 'failed', done); }) })})
function shouldNotHaveHeader(header) { return function (res) { assert.ok(!(header.toLowerCase() in res.headers), 'should not have header ' + header); };}