@@ -178,6 +178,35 @@ describe('createError.isHttpError(val)', function () {
178178 } )
179179} )
180180
181+ describe ( 'Subclass Instantiation' , function ( ) {
182+ it ( 'should allow instantiation of ClientError subclasses' , function ( ) {
183+ assert . doesNotThrow ( ( ) => {
184+ // eslint-disable-next-line no-new
185+ new createError . NotFound ( )
186+ } )
187+ } )
188+
189+ it ( 'should allow instantiation of ServerError subclasses' , function ( ) {
190+ assert . doesNotThrow ( ( ) => {
191+ // eslint-disable-next-line no-new
192+ new createError . InternalServerError ( )
193+ } )
194+ } )
195+ } )
196+
197+ describe ( 'Prototype Chain Adjustments' , function ( ) {
198+ it ( 'CustomError instances should have the correct prototype chain' , function ( ) {
199+ class CustomError extends createError . NotFound { }
200+ const err = new CustomError ( )
201+ assert ( err instanceof CustomError )
202+ assert ( err instanceof createError . NotFound )
203+ // we don't export ClientError currently
204+ // assert(err instanceof createError.ClientError)
205+ assert ( err instanceof createError . HttpError )
206+ assert ( err instanceof Error )
207+ } )
208+ } )
209+
181210describe ( 'HTTP Errors' , function ( ) {
182211 it ( 'createError(status, props)' , function ( ) {
183212 var err = createError ( 404 , {
@@ -336,7 +365,7 @@ describe('HTTP Errors', function () {
336365 assert . strictEqual ( err . expose , false )
337366 } )
338367
339- it ( 'new createError. HttpError() ' , function ( ) {
368+ it ( 'should throw when directly instantiating HttpError' , function ( ) {
340369 assert . throws ( function ( ) {
341370 new createError . HttpError ( ) // eslint-disable-line no-new
342371 } , / c a n n o t c o n s t r u c t a b s t r a c t c l a s s / )
0 commit comments