@@ -34,54 +34,51 @@ test('routes with params and query', async t => {
34
34
t . is ( response , 'Hello world now' )
35
35
} )
36
36
37
- test ( 'async handlers' , async t => {
38
- const hello = async req =>
39
- await Promise . resolve ( `Hello ${ req . params . msg } ${ req . query . time } ` )
40
-
37
+ test ( 'routes with underline' , async t => {
41
38
const routes = router (
42
- get ( '/hello/:msg ' , hello )
39
+ get ( '/foo_bar ' , ( ) => 'Hello with underline' )
43
40
)
44
41
45
42
const url = await server ( routes )
46
- const response = await request ( `${ url } /hello/world?time=now ` )
43
+ const response = await request ( `${ url } /foo_bar ` )
47
44
48
- t . is ( response , 'Hello world now ' )
45
+ t . is ( response , 'Hello with underline ' )
49
46
} )
50
47
51
- test ( 'default 404 handler' , async t => {
52
- const hello = ( ) => 'Hello world'
48
+ test ( 'async handlers' , async t => {
49
+ const hello = req =>
50
+ Promise . resolve ( `Hello ${ req . params . msg } ${ req . query . time } ` )
53
51
54
52
const routes = router (
55
- get ( '/hello' , hello )
53
+ get ( '/hello/:msg ' , hello )
56
54
)
57
55
58
56
const url = await server ( routes )
59
- const helloResponse = await request ( `${ url } /hello` )
60
- t . is ( helloResponse , 'Hello world' )
61
-
62
- const notfoundResponse = await request ( `${ url } /api` , {
63
- simple : false ,
64
- resolveWithFullResponse : true
65
- } )
66
- t . is ( notfoundResponse . statusCode , 404 )
67
- t . is ( notfoundResponse . body , 'Cannot GET /api' )
57
+ const response = await request ( `${ url } /hello/world?time=now` )
58
+
59
+ t . is ( response , 'Hello world now' )
68
60
} )
69
61
70
- test ( 'custom 404 handler' , async t => {
71
- const hello = ( ) => 'Hello world'
72
- const notfound = ( ) => 'Not found'
62
+ test ( 'composed routes' , async t => {
63
+ const fooRouter = router (
64
+ get ( '/foo' , ( ) => `Hello foo` )
65
+ )
66
+
67
+ const barRouter = router (
68
+ get ( '/bar' , ( ) => `Hello bar` )
69
+ )
73
70
74
71
const routes = router (
75
- get ( '/hello' , hello ) ,
76
- get ( '/*' , notfound )
72
+ fooRouter ,
73
+ barRouter
77
74
)
78
75
79
76
const url = await server ( routes )
80
- const helloResponse = await request ( `${ url } /hello ` )
81
- const notfoundResponse = await request ( `${ url } /api ` )
77
+ const fooResponse = await request ( `${ url } /foo ` )
78
+ const barResponse = await request ( `${ url } /bar ` )
82
79
83
- t . is ( helloResponse , 'Hello world ' )
84
- t . is ( notfoundResponse , 'Not found ' )
80
+ t . is ( fooResponse , 'Hello foo ' )
81
+ t . is ( barResponse , 'Hello bar ' )
85
82
} )
86
83
87
84
test ( 'multiple matching routes' , async t => {
@@ -114,7 +111,7 @@ test('multiple matching async routes', async t => {
114
111
t . is ( pathResponse , 'Hello world' )
115
112
} )
116
113
117
- test ( 'error without path and handler' , async t => {
114
+ test ( 'error without path and handler' , t => {
118
115
const fn = ( ) => {
119
116
router ( get ( ) )
120
117
}
@@ -123,7 +120,7 @@ test('error without path and handler', async t => {
123
120
t . is ( error . message , 'You need to set a valid path' )
124
121
} )
125
122
126
- test ( 'error without handler' , async t => {
123
+ test ( 'error without handler' , t => {
127
124
const fn = ( ) => {
128
125
router ( get ( '/hey' ) )
129
126
}
0 commit comments