File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ const isFunction = fn => typeof fn === 'function'
2
2
3
3
export default function composeMiddleware ( middleware ) {
4
4
if ( ! Array . isArray ( middleware ) ) {
5
- throw new TypeError ( 'Middleware stack must be an array! ' )
5
+ throw new TypeError ( 'Stack must be an array' )
6
6
}
7
7
8
8
for ( const fn of middleware ) {
9
9
if ( ! isFunction ( fn ) ) {
10
- throw new TypeError ( 'Middleware must be composed of functions! ' )
10
+ throw new TypeError ( 'Middleware must be composed of functions' )
11
11
}
12
12
}
13
13
Original file line number Diff line number Diff line change
1
+ import { expect } from 'chai'
1
2
import composeMiddleware from '../../../src/utils/compose-middleware'
2
3
3
4
describe ( 'compose middleware' , ( ) => {
4
5
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' , ( ) => {
6
16
return composeMiddleware ( [ ] ) ( )
7
17
} )
8
18
} )
9
19
10
20
describe ( 'with multiple middleware applied' , ( ) => {
11
- it ( 'should workd ' , ( ) => {
21
+ it ( 'execute them with the supplied parameters ' , ( ) => {
12
22
let executionCount = 0
13
23
14
24
const middlewareA = ( req , res , done ) => {
You can’t perform that action at this time.
0 commit comments