-
-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fixing typo in test * adding not-found handler
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = require('./lib/not-found-handler'); |
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
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')); | ||
}; | ||
} |
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
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
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()); | ||
}); | ||
}); |