@@ -5,42 +5,45 @@ import Junction from "../../src/connect/junction";
5
5
describe ( "junction" , function ( ) {
6
6
context ( "when register middlewares" , function ( ) {
7
7
it ( "should connect middleware, the order is register" , function ( done ) {
8
- var junction = new Junction ( ) ;
8
+ let junction = new Junction ( ) ;
9
9
junction . use ( function errorHandling ( error , text , next ) {
10
10
next ( error ) ;
11
11
} ) ;
12
- junction . use ( function toUpper ( text , next ) {
13
- next ( null , text . toLocaleUpperCase ( ) ) ;
12
+ junction . use ( function toUpper ( res , next ) {
13
+ res . value = res . value . toLocaleUpperCase ( ) ;
14
+ next ( ) ;
14
15
} ) ;
15
- junction . use ( function addDesu ( text , next ) {
16
- next ( null , text + " suffix" ) ;
16
+ junction . use ( function addDesu ( res , next ) {
17
+ res . value += " suffix" ;
18
+ next ( ) ;
17
19
} ) ;
18
20
junction . process ( "text" , ( error , result ) => {
19
21
if ( error ) {
20
22
return done ( error ) ;
21
23
}
22
- assert . equal ( result , "TEXT suffix" ) ;
24
+ assert . equal ( result . value , "TEXT suffix" ) ;
23
25
done ( ) ;
24
26
} ) ;
25
27
} ) ;
26
28
} ) ;
27
29
context ( "when occur error in middleware" , function ( ) {
28
30
it ( "should call errorHandling middleware" , function ( done ) {
29
- var junction = new Junction ( ) ;
30
- junction . use ( function toUpper ( text , next ) {
31
- throw new Error ( "ROL" ) ;
31
+ let junction = new Junction ( ) ;
32
+ junction . use ( function toUpper ( res ) {
33
+ throw new Error ( "error on " + res ) ;
32
34
} ) ;
33
- // TODO: 順番に依存してる
34
- junction . use ( function errorHandling ( error , text , next ) {
35
+ junction . use ( function errorHandling ( error , res , next ) {
35
36
assert ( error instanceof Error ) ;
36
- done ( ) ;
37
+ assert . equal ( res . value , "text" ) ;
38
+ next ( ) ;
37
39
} ) ;
38
- junction . process ( "text" , ( error , result ) => {
40
+ junction . process ( "text" , ( error , res ) => {
39
41
if ( error ) {
40
42
return done ( error ) ;
41
43
}
44
+ assert . equal ( res . value , "text" ) ;
42
45
done ( ) ;
43
46
} ) ;
44
47
} ) ;
45
- } )
48
+ } ) ;
46
49
} ) ;
0 commit comments