Throw TypeError for missing root argument

This commit is contained in:
Douglas Christopher Wilson
2014-05-28 17:01:53 -04:00
parent 926ee987fa
commit db91ccac66
2 changed files with 9 additions and 4 deletions
+4 -3
View File
@@ -70,11 +70,12 @@ var mediaType = {
* @api public
*/
exports = module.exports = function directory(root, options){
exports = module.exports = function serveIndex(root, options){
options = options || {};
// root required
if (!root) throw new Error('directory() root path required');
if (!root) throw new TypeError('serveIndex() root path required');
var hidden = options.hidden
, icons = options.icons
, view = options.view || 'tiles'
@@ -83,7 +84,7 @@ exports = module.exports = function directory(root, options){
, template = options.template || defaultTemplate
, stylesheet = options.stylesheet || defaultStylesheet;
return function directory(req, res, next) {
return function serveIndex(req, res, next) {
if ('GET' != req.method && 'HEAD' != req.method) return next();
var url = parse(req.url)
+5 -1
View File
@@ -4,7 +4,11 @@ var request = require('supertest');
var should = require('should');
var serveIndex = require('..');
describe('directory()', function(){
describe('serveIndex(root)', function () {
it('should require root', function () {
serveIndex.should.throw(/root path required/)
})
describe('when given Accept: header', function () {
describe('when Accept: application/json is given', function () {
it('should respond with json', function (done) {