Skip to content

Commit 765c0a8

Browse files
committed
more tests for middleware runner
1 parent 6781d9b commit 765c0a8

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/utils/compose-middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ const isFunction = fn => typeof fn === 'function'
22

33
export default function composeMiddleware (middleware) {
44
if (!Array.isArray(middleware)) {
5-
throw new TypeError('Middleware stack must be an array!')
5+
throw new TypeError('Stack must be an array')
66
}
77

88
for (const fn of middleware) {
99
if (!isFunction(fn)) {
10-
throw new TypeError('Middleware must be composed of functions!')
10+
throw new TypeError('Middleware must be composed of functions')
1111
}
1212
}
1313

test/unit/utils/compose-middleware.spec.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
1+
import { expect } from 'chai'
12
import composeMiddleware from '../../../src/utils/compose-middleware'
23

34
describe('compose middleware', () => {
45
describe('with no middleware', () => {
5-
it('should resolve an empty promise', () => {
6+
it('should fail if a non-array supplied', () => {
7+
expect(() => composeMiddleware(null)).to.throw(TypeError, 'Stack must be an array')
8+
})
9+
10+
it('should fail if the array contains non-function values', () => {
11+
const middleware = [ 'hello', 'world' ]
12+
expect(() => composeMiddleware(middleware)).to.throw(TypeError, 'Middleware must be composed of functions')
13+
})
14+
15+
it('should resolve an empty promise when supplied an empty array', () => {
616
return composeMiddleware([])()
717
})
818
})
919

1020
describe('with multiple middleware applied', () => {
11-
it('should workd', () => {
21+
it('execute them with the supplied parameters', () => {
1222
let executionCount = 0
1323

1424
const middlewareA = (req, res, done) => {

0 commit comments

Comments
 (0)