Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for extending native errors w/o altering prototype #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 18 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ 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 an existing error with HTTP properties without altering its prototype', function () {
const nativeError = new Error('This is a test error')

// Extend the error with HTTP semantics
const 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)
})
})

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