File tree Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Expand file tree Collapse file tree 2 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -8,11 +8,17 @@ export type DoubledObjectWithKey<Key extends string> = {};
8
8
9
9
export type TestDouble < Function > = Function ;
10
10
11
+ export type TestDoubleConstructor < T > = Constructor < T > ;
12
+
11
13
interface Call {
12
14
context : { } ;
13
15
args : any [ ] ;
14
16
}
15
17
18
+ interface Constructor < T > {
19
+ new ( ...args : any [ ] ) : T
20
+ }
21
+
16
22
export interface Captor {
17
23
capture ( ) : any ;
18
24
value ?: any ;
@@ -94,6 +100,16 @@ export function explain<T>(f: TestDouble<T>): Explanation;
94
100
// fake: constructors
95
101
// ----------------------------------------------------------------------------
96
102
103
+ /**
104
+ * Create a fake object constructor the given class.
105
+ *
106
+ * @export
107
+ * @template T
108
+ * @param {{ new (...args: any[]): T } } constructor
109
+ * @returns {DoubledObject<T> }
110
+ */
111
+ export function constructor < T > ( constructor : Constructor < T > ) : TestDoubleConstructor < T > ;
112
+
97
113
//
98
114
// fake: functions
99
115
// ----------------------------------------------------------------------------
@@ -130,7 +146,7 @@ export { functionDouble as func };
130
146
* @param {{ new (...args: any[]): T } } constructor
131
147
* @returns {DoubledObject<T> }
132
148
*/
133
- export function object < T > ( constructor : { new ( ... args : any [ ] ) : T } ) : DoubledObject < T > ;
149
+ export function object < T > ( constructor : Constructor < T > ) : DoubledObject < T > ;
134
150
135
151
/**
136
152
* Create a fake object that has the given list of properties.
Original file line number Diff line number Diff line change @@ -23,9 +23,6 @@ td.when(f(td.matchers.not(false))).thenReject(new Error("rejected"));
23
23
const fakeSum = td . function ( sum ) ;
24
24
td . when ( fakeSum ( 1 , 2 ) ) . thenReturn ( 3 ) ;
25
25
26
- const fakerSum = td . function ( "sum" ) ;
27
- td . when ( fakerSum ( 1 , 2 ) ) . thenReturn ( 3 ) ;
28
-
29
26
const fakestSum = td . function ( "sum" ) ;
30
27
td . when ( fakestSum ( 1 , 2 ) ) . thenReturn ( 3 ) ;
31
28
@@ -40,7 +37,8 @@ td.when(ff(td.matchers.not(false))).thenReject(new Error("rejected"));
40
37
41
38
// td.constructor()
42
39
43
- const dog = td . constructor ( Dog ) ;
40
+ const DogFake = td . constructor ( Dog ) ;
41
+ const dog = new DogFake ( )
44
42
td . when ( dog . bark ( ) ) . thenReturn ( "bark!" ) ;
45
43
46
44
// td.object()
You can’t perform that action at this time.
0 commit comments