Skip to content

Commit

Permalink
Not found (#45)
Browse files Browse the repository at this point in the history
* fixing typo in test

* adding not-found handler
  • Loading branch information
ekryski authored and daffl committed Aug 21, 2018
1 parent c9fbd6a commit 8c245cd
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/errors/not-found.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./lib/not-found-handler');
7 changes: 7 additions & 0 deletions packages/errors/src/not-found-handler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import errors from './index';

export default function() {
return function(req, res, next) {
next(new errors.NotFound('Page not found'));
};
}
2 changes: 1 addition & 1 deletion packages/errors/test/error-handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const jsonHandler = sinon.spy(function(error, req, res, next) {
res.json(error);
});

describe('feathers-errors', () => {
describe('error-handler', () => {
it('is CommonJS compatible', () => {
expect(typeof require('../lib/error-handler')).to.equal('function');
});
Expand Down
34 changes: 34 additions & 0 deletions packages/errors/test/not-found-handler.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*jshint expr: true, unused: false*/

if(!global._babelPolyfill) { require('babel-polyfill'); }

import chai, { expect } from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import { errors } from '../src';
import handler from '../src/not-found-handler';

chai.use(sinonChai);

const mockRequest = {};
const mockResponse = {};
const mockNext = sinon.spy(() => {});

describe('not-found-handler', () => {
it('is CommonJS compatible', () => {
expect(typeof require('../lib/not-found-handler')).to.equal('function');
});

it('can be required at the root', () => {
expect(typeof require('../not-found')).to.equal('function');
});

it('is import compatible', () => {
expect(typeof handler).to.equal('function');
});

it('returns NotFound error', () => {
handler()(mockRequest, mockResponse, mockNext);
expect(mockNext).to.have.been.calledWith(new errors.NotFound());
});
});

0 comments on commit 8c245cd

Please sign in to comment.