3
3
* @module errnode/types/tests/unit-d/NodeErrorConstructor
4
4
*/
5
5
6
+ import type { Times } from '@flex-development/tutils'
6
7
import type NodeError from '../node-error'
7
8
import type TestSubject from '../node-error-constructor'
8
9
9
10
describe ( 'unit-d:types/NodeErrorConstructor' , ( ) => {
10
- it ( 'should extract parameters of type any[] if M extends string' , ( ) => {
11
- expectTypeOf < TestSubject > ( ) . parameters . toEqualTypeOf < any [ ] > ( )
12
- expectTypeOf < TestSubject > ( ) . constructorParameters . toEqualTypeOf < any [ ] > ( )
13
- } )
14
-
15
- it ( 'should extract parameters of type M if M extends any[]' , ( ) => {
16
- // Arrange
17
- type B = ErrorConstructor
18
- type M = [ string , string , string ]
19
-
20
- expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < M > ( )
21
- expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < M > ( )
22
- } )
23
-
24
- it ( 'should extract parameters of type Parameters<M> if M extends MessageFn' , ( ) => {
25
- type B = TypeErrorConstructor
26
- type M = ( ext : string , path : string ) => string
27
- type P = Parameters < M >
28
-
29
- expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < P > ( )
30
- expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < P > ( )
31
- } )
32
-
33
11
it ( 'should match [prototype: NodeError<T>]' , ( ) => {
34
12
expectTypeOf < TestSubject > ( )
35
13
. toHaveProperty ( 'prototype' )
@@ -45,4 +23,42 @@ describe('unit-d:types/NodeErrorConstructor', () => {
45
23
NodeError < TypeError >
46
24
> ( )
47
25
} )
26
+
27
+ describe ( 'M extends MessageFn' , ( ) => {
28
+ it ( 'should be callable with Parameters<M>' , ( ) => {
29
+ // Arrange
30
+ type B = TypeErrorConstructor
31
+ type M = ( ext : string , path : string ) => string
32
+ type P = Parameters < M >
33
+
34
+ // Expect
35
+ expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < P > ( )
36
+ expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < P > ( )
37
+ } )
38
+ } )
39
+
40
+ describe ( 'M extends string' , ( ) => {
41
+ it ( 'should be callable with any[]' , ( ) => {
42
+ // Arrange
43
+ type B = ErrorConstructor
44
+ type M = string
45
+ type P = any [ ]
46
+
47
+ // Expect
48
+ expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < P > ( )
49
+ expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < P > ( )
50
+ } )
51
+ } )
52
+
53
+ describe ( 'M extends unknown[]' , ( ) => {
54
+ it ( 'should be callable with M' , ( ) => {
55
+ // Arrange
56
+ type B = ErrorConstructor
57
+ type M = Times < 3 , string >
58
+
59
+ // Expect
60
+ expectTypeOf < TestSubject < B , M > > ( ) . parameters . toEqualTypeOf < M > ( )
61
+ expectTypeOf < TestSubject < B , M > > ( ) . constructorParameters . toEqualTypeOf < M > ( )
62
+ } )
63
+ } )
48
64
} )
0 commit comments