@@ -131,37 +131,59 @@ describe("StaticFileHandler", function () {
131
131
} )
132
132
} )
133
133
134
- it ( "should return 404 when no path parameters" , function ( ) {
135
- const event = mockEvent ( { path : "doesntexist.404" } )
136
- let h = new StaticFileHandler ( STATIC_FILES_PATH )
137
- const response = h . get ( event , null )
138
- return expect ( response )
139
- . to . eventually . haveOwnProperty ( "statusCode" )
140
- . that . equals ( 404 )
141
- } )
134
+ describe ( "error response" , function ( ) {
135
+ it ( "should include viewData in default error page" , function ( ) {
136
+ const event = mockEvent ( { path : "doesntexist.404" } )
137
+ let h = new StaticFileHandler ( STATIC_FILES_PATH )
138
+ const response = h . get ( event , null )
139
+ // the default error page mentions page name and "does not exist"
140
+ return expect ( response )
141
+ . to . eventually . haveOwnProperty ( "body" )
142
+ . that . matches ( / d o e s n t e x i s t \. 4 0 4 d o e s n o t e x i s t / )
143
+ } )
142
144
143
- it ( "should return 404 customErrorPagePath is invalid" , function ( ) {
144
- const event = mockEvent ( { path : "doesntexist.404" } )
145
- let h = new StaticFileHandler (
146
- STATIC_FILES_PATH ,
147
- "error-page-doesnt-exist-either.html"
148
- )
149
- const response = h . get ( event , null )
150
- return expect ( response )
151
- . to . eventually . haveOwnProperty ( "statusCode" )
152
- . that . equals ( 404 )
153
- } )
145
+ it ( "should include viewData in custom error page" , function ( ) {
146
+ const event = mockEvent ( { path : "doesntexist.404" } )
147
+ let h = new StaticFileHandler ( STATIC_FILES_PATH , "custom-error.html" )
148
+ const response = h . get ( event , null )
149
+ // the default error page mentions page name and "does not exist"
150
+ return expect ( response )
151
+ . to . eventually . haveOwnProperty ( "body" )
152
+ . that . matches ( / d o e s n t e x i s t \. 4 0 4 d o e s n o t e x i s t / )
153
+ } )
154
154
155
- it ( "should use customErrorPagePath" , async function ( ) {
156
- const event = mockEvent ( { path : "doesntexist.404" } )
157
- let h = new StaticFileHandler ( STATIC_FILES_PATH , "custom-error.html" )
158
- const response = h . get ( event , null )
159
- expect ( response )
160
- . to . eventually . haveOwnProperty ( "statusCode" )
161
- . that . equals ( 404 )
162
- return expect ( response )
163
- . to . eventually . haveOwnProperty ( "body" )
164
- . that . matches ( / < t i t l e > C U S T O M < \/ t i t l e > / )
155
+ it ( "should return 404 when no path parameters" , function ( ) {
156
+ const event = mockEvent ( { path : "doesntexist.404" } )
157
+ let h = new StaticFileHandler ( STATIC_FILES_PATH )
158
+ const response = h . get ( event , null )
159
+ return expect ( response )
160
+ . to . eventually . haveOwnProperty ( "statusCode" )
161
+ . that . equals ( 404 )
162
+ } )
163
+
164
+ it ( "should return 404 customErrorPagePath is invalid" , function ( ) {
165
+ const event = mockEvent ( { path : "doesntexist.404" } )
166
+ let h = new StaticFileHandler (
167
+ STATIC_FILES_PATH ,
168
+ "error-page-doesnt-exist-either.html"
169
+ )
170
+ const response = h . get ( event , null )
171
+ return expect ( response )
172
+ . to . eventually . haveOwnProperty ( "statusCode" )
173
+ . that . equals ( 404 )
174
+ } )
175
+
176
+ it ( "should use customErrorPagePath" , async function ( ) {
177
+ const event = mockEvent ( { path : "doesntexist.404" } )
178
+ let h = new StaticFileHandler ( STATIC_FILES_PATH , "custom-error.html" )
179
+ const response = h . get ( event , null )
180
+ expect ( response )
181
+ . to . eventually . haveOwnProperty ( "statusCode" )
182
+ . that . equals ( 404 )
183
+ return expect ( response )
184
+ . to . eventually . haveOwnProperty ( "body" )
185
+ . that . matches ( / < t i t l e > C U S T O M < \/ t i t l e > / )
186
+ } )
165
187
} )
166
188
167
189
/**
0 commit comments