Skip to content

Commit 6d8791e

Browse files
committed
Added test for ES6 classes interoperability
1 parent d2fe4f3 commit 6d8791e

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,4 +406,26 @@ describe('HTTP Errors', function () {
406406
assert(util.isError(new createError['500']()))
407407
/* eslint-enable node/no-deprecated-api */
408408
})
409+
410+
it('should interoperate with ES6 classes', function () {
411+
class MyHttpError extends createError.HttpError {
412+
constructor () {
413+
super()
414+
this.name = 'MyHttpError'
415+
this.message = 'ES6 class HTTPError'
416+
this.status = 404
417+
this.myProp = 'test'
418+
}
419+
}
420+
421+
// Testing PR#99: This line should not throw TypeError('cannot construct abstract class')
422+
const err = new MyHttpError()
423+
assert.strictEqual(err.name, 'MyHttpError')
424+
assert.strictEqual(err.message, 'ES6 class HTTPError')
425+
assert.strictEqual(err.status, 404)
426+
assert.strictEqual(err.myProp, 'test')
427+
/* eslint-disable-next-line node/no-deprecated-api */
428+
assert.strictEqual(util.isError(err), true)
429+
assert.strictEqual(createError.isHttpError(err), true)
430+
})
409431
})

0 commit comments

Comments
 (0)