11import test from 'ava'
22
3- import { Substitute , SubstituteOf , clearSubstitute , received } from '../src'
3+ import { Substitute , SubstituteOf , clearReceivedCalls , received } from '../src'
44import { SubstituteNode } from '../src/SubstituteNode'
55
66interface Calculator {
@@ -14,51 +14,15 @@ type InstanceReturningSubstitute<T> = SubstituteOf<T> & {
1414 [ SubstituteNode . instance ] : SubstituteNode
1515}
1616
17- test ( 'clears everything on a substitute' , t => {
18- const calculator = Substitute . for < Calculator > ( ) as InstanceReturningSubstitute < Calculator >
19- calculator . add ( 1 , 1 )
20- calculator [ received ] ( ) . add ( 1 , 1 )
21- calculator [ clearSubstitute ] ( )
22-
23- t . is ( calculator [ SubstituteNode . instance ] . recorder . records . size , 0 )
24- t . is ( calculator [ SubstituteNode . instance ] . recorder . indexedRecords . size , 0 )
25-
26- t . throws ( ( ) => calculator [ received ] ( ) . add ( 1 , 1 ) )
27-
28- // explicitly using 'all'
29- calculator . add ( 1 , 1 )
30- calculator . received ( ) . add ( 1 , 1 )
31- calculator . clearSubstitute ( 'all' )
32-
33- t . is ( calculator [ SubstituteNode . instance ] . recorder . records . size , 0 )
34- t . is ( calculator [ SubstituteNode . instance ] . recorder . indexedRecords . size , 0 )
35-
36- t . throws ( ( ) => calculator . received ( ) . add ( 1 , 1 ) )
37- } )
38-
3917test ( 'clears received calls on a substitute' , t => {
4018 const calculator = Substitute . for < Calculator > ( ) as InstanceReturningSubstitute < Calculator >
4119 calculator . add ( 1 , 1 )
4220 calculator . add ( 1 , 1 ) . returns ( 2 )
43- calculator . clearSubstitute ( 'receivedCalls' )
21+ calculator [ clearReceivedCalls ] ( ) ;
4422
4523 t . is ( calculator [ SubstituteNode . instance ] . recorder . records . size , 2 )
4624 t . is ( calculator [ SubstituteNode . instance ] . recorder . indexedRecords . size , 2 )
4725
48- t . throws ( ( ) => calculator . received ( ) . add ( 1 , 1 ) )
26+ t . throws ( ( ) => calculator [ received ] ( ) . add ( 1 , 1 ) )
4927 t . is ( 2 , calculator . add ( 1 , 1 ) )
50- } )
51-
52- test ( 'clears return values on a substitute' , t => {
53- const calculator = Substitute . for < Calculator > ( ) as InstanceReturningSubstitute < Calculator >
54- calculator . add ( 1 , 1 )
55- calculator . add ( 1 , 1 ) . returns ( 2 )
56- calculator . clearSubstitute ( 'substituteValues' )
57-
58- t . is ( calculator [ SubstituteNode . instance ] . recorder . records . size , 2 )
59- t . is ( calculator [ SubstituteNode . instance ] . recorder . indexedRecords . size , 2 )
60-
61- t . notThrows ( ( ) => calculator . received ( ) . add ( 1 , 1 ) )
62- // @ts -expect-error
63- t . true ( calculator . add ( 1 , 1 ) [ SubstituteNode . instance ] instanceof SubstituteNode )
6428} )
0 commit comments