@@ -8,12 +8,26 @@ class Dog {
8
8
bark ( ) { }
9
9
}
10
10
11
+ class Cat {
12
+ constructor ( ) { } ;
13
+ meow ( ) : string { return "meow! meow!" }
14
+ }
15
+
16
+ function sum ( first : number , second : number ) : number {
17
+ return first + second
18
+ }
19
+
20
+
11
21
const dog = td . constructor ( Dog ) ;
12
22
td . when ( dog . prototype . bark ( ) ) . thenReturn ( "woof!" ) ;
13
23
14
24
const bird = td . object ( { fly : function ( ) { } } ) ;
15
25
td . when ( bird . fly ( ) ) . thenReturn ( "swoosh!" ) ;
16
26
27
+ const kitty = td . object ( [ "scratch" , "meow" ] ) ;
28
+ td . when ( kitty . scratch ( ) ) . thenReturn ( "scratch!" ) ;
29
+ td . when ( kitty . meow ( ) ) . thenReturn ( "meow!" ) ;
30
+
17
31
if ( eval ( "typeof Proxy" ) !== "undefined" ) {
18
32
class Bear { constructor ( ) { } ; sleep ( ) { } ; } ;
19
33
const bear = td . object < Bear > ( "A bear" ) ;
@@ -36,12 +50,22 @@ td.when(f(td.matchers.isA(String))).thenDo(function(s: string) { return s; });
36
50
td . when ( f ( td . matchers . not ( true ) ) ) . thenResolve ( "value1" , "value2" ) ;
37
51
td . when ( f ( td . matchers . not ( false ) ) ) . thenReject ( new Error ( "rejected" ) ) ;
38
52
53
+ const fakeSum = td . function ( sum ) ;
54
+ td . when ( fakeSum ( 1 , 2 ) ) . thenReturn ( 3 ) ;
55
+
56
+ const fakestSum = td . function ( "sum" ) ;
57
+ td . when ( fakestSum ( 1 , 2 ) ) . thenReturn ( 3 ) ;
58
+
39
59
f ( )
40
60
td . verify ( f ( ) ) ;
41
61
td . verify ( f ( ) , { times : 1 } ) ;
42
62
td . verify ( f ( ) , { ignoreExtraArgs : false } ) ;
43
63
td . verify ( f ( ) , { ignoreExtraArgs : true , times : 1 } ) ;
44
64
65
+ const CatFake = td . constructor ( Cat ) ;
66
+ const cat = new CatFake ( )
67
+ td . when ( cat . meow ( ) ) . thenReturn ( "moo!" ) ;
68
+
45
69
const explanation = td . explain ( f ) ;
46
70
47
71
console . log (
0 commit comments