Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,26 @@ describe('createError(status)', function () {
assert.ok(util.isError(createError(500))) // eslint-disable-line node/no-deprecated-api
})

describe('Extending Existing Errors with HTTP Properties', function () {
it('should extend existing error without altering its prototype or replacing the object', function () {
var nativeError = new Error('This is a test error')

// Extend the error with HTTP semantics
var httpError = createError(404, nativeError, { expose: false })

assert.strictEqual(httpError.status, 404)
assert.strictEqual(httpError.expose, false)

assert.strictEqual(httpError.message, 'This is a test error')

assert(httpError instanceof Error)

assert.strictEqual(Object.getPrototypeOf(httpError), Error.prototype)

assert.strictEqual(httpError, nativeError)
})
})

describe('when status 300', function () {
before(function () {
this.error = createError(300)
Expand Down
Loading