Skip to content

Commit 94d0441

Browse files
committed
feat(models): ERR_ILLEGAL_CONSTRUCTOR
Signed-off-by: Lexus Drumgold <[email protected]>
1 parent 567b160 commit 94d0441

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* @file Unit Tests - ERR_ILLEGAL_CONSTRUCTOR
3+
* @module errnode/models/tests/unit/ERR_ILLEGAL_CONSTRUCTOR
4+
*/
5+
6+
import { ErrorCode } from '#src/enums'
7+
import type { NodeError } from '#src/types'
8+
import TestSubject from '../err-illegal-constructor'
9+
10+
describe('unit:models/ERR_ILLEGAL_CONSTRUCTOR', () => {
11+
let result: NodeError<TypeError>
12+
13+
beforeEach(() => {
14+
result = new TestSubject()
15+
})
16+
17+
it('should return TypeError instance', () => {
18+
expect(result).to.have.property('name').equal('TypeError')
19+
expect(result).to.be.instanceof(TypeError)
20+
})
21+
22+
it('should set error code', () => {
23+
expect(result)
24+
.to.have.property('code')
25+
.equal(ErrorCode.ERR_ILLEGAL_CONSTRUCTOR)
26+
})
27+
28+
it('should set error message', () => {
29+
expect(result).to.have.property('message').equal('Illegal constructor')
30+
})
31+
})

src/models/err-illegal-constructor.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @file Error Models - ERR_ILLEGAL_CONSTRUCTOR
3+
* @module errnode/models/ERR_ILLEGAL_CONSTRUCTOR
4+
* @see https://github.com/nodejs/node/blob/v19.3.0/lib/internal/errors.js#L1163
5+
*/
6+
7+
import { ErrorCode } from '#src/enums'
8+
import type { NodeError, NodeErrorConstructor } from '#src/types'
9+
import { createNodeError } from '#src/utils'
10+
11+
/**
12+
* `ERR_ILLEGAL_CONSTRUCTOR` model.
13+
*
14+
* Thrown when an attempt is made to construct an object using a non-public
15+
* constructor.
16+
*
17+
* @see https://nodejs.org/api/errors.html#err_illegal_constructor
18+
*
19+
* @class
20+
*
21+
* @return {NodeError<TypeError>} `TypeError` instance
22+
*/
23+
const ERR_ILLEGAL_CONSTRUCTOR: NodeErrorConstructor<TypeErrorConstructor, []> =
24+
createNodeError(
25+
ErrorCode.ERR_ILLEGAL_CONSTRUCTOR,
26+
TypeError,
27+
'Illegal constructor'
28+
)
29+
30+
export default ERR_ILLEGAL_CONSTRUCTOR

src/models/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
export { default as ERR_AMBIGUOUS_ARGUMENT } from './err-ambiguous-argument'
88
export { default as ERR_ARG_NOT_ITERABLE } from './err-arg-not-iterable'
99
export { default as ERR_ASYNC_CALLBACK } from './err-async-callback'
10+
export { default as ERR_ILLEGAL_CONSTRUCTOR } from './err-illegal-constructor'

0 commit comments

Comments
 (0)