11import test from 'ava'
22
3- import { Substitute , Arg , SubstituteOf } from '../../src'
3+ import { Substitute , Arg , SubstituteOf , received , mimicks , resolves , returns } from '../../src'
44
55class Dummy {
66
@@ -47,22 +47,13 @@ function initialize() {
4747
4848const textModifierRegex = / \x1b \[ \d + m / g
4949
50- test ( 'class with method called \'received\' can be used for call count verification when proxies are suspended ' , t => {
50+ test ( 'class with method called \'received\' can be used for call count verification when using symbols ' , t => {
5151 initialize ( )
5252
53- Substitute . disableFor ( substitute ) . received ( 2 )
53+ substitute . received ( 2 )
5454
55- t . throws ( ( ) => substitute . received ( 2 ) . received ( 2 ) )
56- t . notThrows ( ( ) => substitute . received ( 1 ) . received ( 2 ) )
57- } )
58-
59- test ( 'class with method called \'received\' can be used for call count verification' , t => {
60- initialize ( )
61-
62- Substitute . disableFor ( substitute ) . received ( 'foo' )
63-
64- t . notThrows ( ( ) => substitute . received ( 1 ) . received ( 'foo' ) )
65- t . throws ( ( ) => substitute . received ( 2 ) . received ( 'foo' ) )
55+ t . throws ( ( ) => substitute [ received ] ( 2 ) . received ( 2 ) )
56+ t . notThrows ( ( ) => substitute [ received ] ( 1 ) . received ( 2 ) )
6657} )
6758
6859test ( 'class string field set received' , t => {
@@ -79,30 +70,30 @@ test('class string field set received', t => {
7970 runLogic ( substitute )
8071
8172
82- t . notThrows ( ( ) => substitute . received ( ) . v = 'hello' )
83- t . notThrows ( ( ) => substitute . received ( 5 ) . v = Arg . any ( ) )
84- t . notThrows ( ( ) => substitute . received ( ) . v = Arg . any ( ) )
85- t . notThrows ( ( ) => substitute . received ( 2 ) . v = 'hello' )
86- t . notThrows ( ( ) => substitute . received ( 2 ) . v = Arg . is ( x => typeof x === 'string' && x . indexOf ( 'll' ) > - 1 ) )
73+ t . notThrows ( ( ) => substitute [ received ] ( ) . v = 'hello' )
74+ t . notThrows ( ( ) => substitute [ received ] ( 5 ) . v = Arg . any ( ) )
75+ t . notThrows ( ( ) => substitute [ received ] ( ) . v = Arg . any ( ) )
76+ t . notThrows ( ( ) => substitute [ received ] ( 2 ) . v = 'hello' )
77+ t . notThrows ( ( ) => substitute [ received ] ( 2 ) . v = Arg . is ( x => typeof x === 'string' && x . indexOf ( 'll' ) > - 1 ) )
8778
88- t . throws ( ( ) => substitute . received ( 2 ) . v = Arg . any ( ) )
89- t . throws ( ( ) => substitute . received ( 1 ) . v = Arg . any ( ) )
90- t . throws ( ( ) => substitute . received ( 1 ) . v = Arg . is ( x => typeof x === 'string' && x . indexOf ( 'll' ) > - 1 ) )
91- t . throws ( ( ) => substitute . received ( 3 ) . v = 'hello' )
79+ t . throws ( ( ) => substitute [ received ] ( 2 ) . v = Arg . any ( ) )
80+ t . throws ( ( ) => substitute [ received ] ( 1 ) . v = Arg . any ( ) )
81+ t . throws ( ( ) => substitute [ received ] ( 1 ) . v = Arg . is ( x => typeof x === 'string' && x . indexOf ( 'll' ) > - 1 ) )
82+ t . throws ( ( ) => substitute [ received ] ( 3 ) . v = 'hello' )
9283} )
9384
9485test ( 'resolving promises works' , async t => {
9586 initialize ( )
9687
97- substitute . returnPromise ( ) . resolves ( 1338 )
88+ substitute . returnPromise ( ) [ resolves ] ( 1338 )
9889
9990 t . is ( 1338 , await substitute . returnPromise ( ) as number )
10091} )
10192
10293test ( 'class void returns' , t => {
10394 initialize ( )
10495
105- substitute . foo ( ) . returns ( void 0 , null )
96+ substitute . foo ( ) [ returns ] ( void 0 , null )
10697
10798 t . is ( substitute . foo ( ) , void 0 )
10899 t . is ( substitute . foo ( ) , null )
@@ -117,9 +108,9 @@ test('class method received', t => {
117108 void substitute . c ( 'hi' , 'there' )
118109 void substitute . c ( 'hi' , 'there' )
119110
120- t . notThrows ( ( ) => substitute . received ( 4 ) . c ( 'hi' , 'there' ) )
121- t . notThrows ( ( ) => substitute . received ( 1 ) . c ( 'hi' , 'the1re' ) )
122- t . notThrows ( ( ) => substitute . received ( ) . c ( 'hi' , 'there' ) )
111+ t . notThrows ( ( ) => substitute [ received ] ( 4 ) . c ( 'hi' , 'there' ) )
112+ t . notThrows ( ( ) => substitute [ received ] ( 1 ) . c ( 'hi' , 'the1re' ) )
113+ t . notThrows ( ( ) => substitute [ received ] ( ) . c ( 'hi' , 'there' ) )
123114
124115 const expectedMessage = 'Expected 7 calls to the method c with arguments [\'hi\', \'there\'], but received 4 of such calls.\n' +
125116 'All calls received to method c:\n' +
@@ -128,32 +119,32 @@ test('class method received', t => {
128119 '-> call with arguments [\'hi\', \'there\']\n' +
129120 '-> call with arguments [\'hi\', \'there\']\n' +
130121 '-> call with arguments [\'hi\', \'there\']'
131- const { message } = t . throws ( ( ) => { substitute . received ( 7 ) . c ( 'hi' , 'there' ) } )
122+ const { message } = t . throws ( ( ) => { substitute [ received ] ( 7 ) . c ( 'hi' , 'there' ) } )
132123 t . is ( message . replace ( textModifierRegex , '' ) , expectedMessage )
133124} )
134125
135126test ( 'received call matches after partial mocks using property instance mimicks' , t => {
136127 initialize ( )
137128
138- substitute . d . mimicks ( ( ) => instance . d )
129+ substitute . d [ mimicks ] ( ( ) => instance . d )
139130 substitute . c ( 'lala' , 'bar' )
140131
141- substitute . received ( 1 ) . c ( 'lala' , 'bar' )
142- substitute . received ( 1 ) . c ( 'lala' , 'bar' )
132+ substitute [ received ] ( 1 ) . c ( 'lala' , 'bar' )
133+ substitute [ received ] ( 1 ) . c ( 'lala' , 'bar' )
143134
144- t . notThrows ( ( ) => substitute . received ( 1 ) . c ( 'lala' , 'bar' ) )
135+ t . notThrows ( ( ) => substitute [ received ] ( 1 ) . c ( 'lala' , 'bar' ) )
145136 const expectedMessage = 'Expected 2 calls to the method c with arguments [\'lala\', \'bar\'], but received 1 of such calls.\n' +
146137 'All calls received to method c:\n' +
147138 '-> call with arguments [\'lala\', \'bar\']'
148- const { message } = t . throws ( ( ) => substitute . received ( 2 ) . c ( 'lala' , 'bar' ) )
139+ const { message } = t . throws ( ( ) => substitute [ received ] ( 2 ) . c ( 'lala' , 'bar' ) )
149140 t . is ( message . replace ( textModifierRegex , '' ) , expectedMessage )
150141 t . deepEqual ( substitute . d , 1337 )
151142} )
152143
153144test ( 'partial mocks using property instance mimicks' , t => {
154145 initialize ( )
155146
156- substitute . d . mimicks ( ( ) => instance . d )
147+ substitute . d [ mimicks ] ( ( ) => instance . d )
157148
158149 t . deepEqual ( substitute . d , 1337 )
159150} )
0 commit comments