Skip to content

Commit

Permalink
feat(models): ERR_ILLEGAL_CONSTRUCTOR
Browse files Browse the repository at this point in the history
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
  • Loading branch information
unicornware committed Dec 30, 2022
1 parent 567b160 commit 94d0441
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/models/__tests__/err-illegal-constructor.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* @file Unit Tests - ERR_ILLEGAL_CONSTRUCTOR
* @module errnode/models/tests/unit/ERR_ILLEGAL_CONSTRUCTOR
*/

import { ErrorCode } from '#src/enums'
import type { NodeError } from '#src/types'
import TestSubject from '../err-illegal-constructor'

describe('unit:models/ERR_ILLEGAL_CONSTRUCTOR', () => {
let result: NodeError<TypeError>

beforeEach(() => {
result = new TestSubject()
})

it('should return TypeError instance', () => {
expect(result).to.have.property('name').equal('TypeError')
expect(result).to.be.instanceof(TypeError)
})

it('should set error code', () => {
expect(result)
.to.have.property('code')
.equal(ErrorCode.ERR_ILLEGAL_CONSTRUCTOR)
})

it('should set error message', () => {
expect(result).to.have.property('message').equal('Illegal constructor')
})
})
30 changes: 30 additions & 0 deletions src/models/err-illegal-constructor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @file Error Models - ERR_ILLEGAL_CONSTRUCTOR
* @module errnode/models/ERR_ILLEGAL_CONSTRUCTOR
* @see https://github.com/nodejs/node/blob/v19.3.0/lib/internal/errors.js#L1163
*/

import { ErrorCode } from '#src/enums'
import type { NodeError, NodeErrorConstructor } from '#src/types'
import { createNodeError } from '#src/utils'

/**
* `ERR_ILLEGAL_CONSTRUCTOR` model.
*
* Thrown when an attempt is made to construct an object using a non-public
* constructor.
*
* @see https://nodejs.org/api/errors.html#err_illegal_constructor
*
* @class
*
* @return {NodeError<TypeError>} `TypeError` instance
*/
const ERR_ILLEGAL_CONSTRUCTOR: NodeErrorConstructor<TypeErrorConstructor, []> =
createNodeError(
ErrorCode.ERR_ILLEGAL_CONSTRUCTOR,
TypeError,
'Illegal constructor'
)

export default ERR_ILLEGAL_CONSTRUCTOR
1 change: 1 addition & 0 deletions src/models/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
export { default as ERR_AMBIGUOUS_ARGUMENT } from './err-ambiguous-argument'
export { default as ERR_ARG_NOT_ITERABLE } from './err-arg-not-iterable'
export { default as ERR_ASYNC_CALLBACK } from './err-async-callback'
export { default as ERR_ILLEGAL_CONSTRUCTOR } from './err-illegal-constructor'

0 comments on commit 94d0441

Please sign in to comment.