1- import { describe , it , iit , ddescribe , expect , tick , async } from 'test_lib/test_lib' ;
1+ import { describe , it , iit , ddescribe , expect , tick , async , SpyObject , beforeEach } from 'test_lib/test_lib' ;
22import { MapWrapper , ListWrapper } from 'facade/collection' ;
33import { PromiseWrapper } from 'facade/async' ;
4+ import { IMPLEMENTS , proxy } from 'facade/lang' ;
45
56class TestObj {
67 prop ;
@@ -9,6 +10,10 @@ class TestObj {
910 }
1011}
1112
13+ @proxy
14+ @IMPLEMENTS ( TestObj )
15+ class SpyTestObj extends SpyObject { noSuchMethod ( m ) { return super . noSuchMethod ( m ) } }
16+
1217export function main ( ) {
1318 describe ( 'test_lib' , ( ) => {
1419 describe ( 'equality' , ( ) => {
@@ -48,5 +53,29 @@ export function main() {
4853 expect ( MapWrapper . createFromStringMap ( { 'a' : 1 } ) ) . not . toEqual ( MapWrapper . createFromStringMap ( { 'a' : 1 , 'b' : 1 } ) ) ;
4954 } ) ;
5055 } ) ;
56+
57+ describe ( "spy objects" , ( ) => {
58+ var spyObj ;
59+
60+ beforeEach ( ( ) => {
61+ spyObj = new SpyTestObj ( ) ;
62+ } ) ;
63+
64+ it ( "should pass the runtime check" , ( ) => {
65+ var t :TestObj = spyObj ;
66+ expect ( t ) . toBeDefined ( ) ;
67+ } ) ;
68+
69+ it ( "should return a new spy func with no calls" , ( ) => {
70+ expect ( spyObj . spy ( "someFunc" ) ) . not . toHaveBeenCalled ( ) ;
71+ } ) ;
72+
73+ it ( "should record function calls" , ( ) => {
74+ spyObj . spy ( "someFunc" ) . andCallFake ( ( a , b ) => a + b ) ;
75+
76+ expect ( spyObj . someFunc ( 1 , 2 ) ) . toEqual ( 3 ) ;
77+ expect ( spyObj . spy ( "someFunc" ) ) . toHaveBeenCalledWith ( 1 , 2 ) ;
78+ } ) ;
79+ } ) ;
5180 } ) ;
5281}
0 commit comments