@@ -30,127 +30,150 @@ function throwsException(fake, error, message) {
3030 }
3131}
3232
33+ const SKIP_OPTIONS_FOR_YIELDS = {
34+ skipReturn : true ,
35+ skipThrows : true ,
36+ } ;
37+
38+ function clear ( fake , options ) {
39+ fake . fakeFn = undefined ;
40+
41+ fake . callsThrough = undefined ;
42+ fake . callsThroughWithNew = undefined ;
43+
44+ if ( ! options || ! options . skipThrows ) {
45+ fake . exception = undefined ;
46+ fake . exceptionCreator = undefined ;
47+ fake . throwArgAt = undefined ;
48+ }
49+
50+ fake . callArgAt = undefined ;
51+ fake . callbackArguments = undefined ;
52+ fake . callbackContext = undefined ;
53+ fake . callArgProp = undefined ;
54+ fake . callbackAsync = undefined ;
55+
56+ if ( ! options || ! options . skipReturn ) {
57+ fake . returnValue = undefined ;
58+ fake . returnValueDefined = undefined ;
59+ fake . returnArgAt = undefined ;
60+ fake . returnThis = undefined ;
61+ }
62+
63+ fake . resolve = undefined ;
64+ fake . resolveThis = undefined ;
65+ fake . resolveArgAt = undefined ;
66+
67+ fake . reject = undefined ;
68+ }
69+
3370const defaultBehaviors = {
3471 callsFake : function callsFake ( fake , fn ) {
72+ clear ( fake ) ;
73+
3574 fake . fakeFn = fn ;
36- fake . exception = undefined ;
37- fake . exceptionCreator = undefined ;
3875 } ,
3976
4077 callsArg : function callsArg ( fake , index ) {
4178 if ( typeof index !== "number" ) {
4279 throw new TypeError ( "argument index is not number" ) ;
4380 }
81+ clear ( fake ) ;
4482
4583 fake . callArgAt = index ;
4684 fake . callbackArguments = [ ] ;
47- fake . callbackContext = undefined ;
48- fake . callArgProp = undefined ;
49- fake . callbackAsync = false ;
5085 } ,
5186
5287 callsArgOn : function callsArgOn ( fake , index , context ) {
5388 if ( typeof index !== "number" ) {
5489 throw new TypeError ( "argument index is not number" ) ;
5590 }
91+ clear ( fake ) ;
5692
5793 fake . callArgAt = index ;
5894 fake . callbackArguments = [ ] ;
5995 fake . callbackContext = context ;
60- fake . callArgProp = undefined ;
61- fake . callbackAsync = false ;
6296 } ,
6397
6498 callsArgWith : function callsArgWith ( fake , index ) {
6599 if ( typeof index !== "number" ) {
66100 throw new TypeError ( "argument index is not number" ) ;
67101 }
102+ clear ( fake ) ;
68103
69104 fake . callArgAt = index ;
70105 fake . callbackArguments = slice ( arguments , 2 ) ;
71- fake . callbackContext = undefined ;
72- fake . callArgProp = undefined ;
73- fake . callbackAsync = false ;
74106 } ,
75107
76108 callsArgOnWith : function callsArgWith ( fake , index , context ) {
77109 if ( typeof index !== "number" ) {
78110 throw new TypeError ( "argument index is not number" ) ;
79111 }
112+ clear ( fake ) ;
80113
81114 fake . callArgAt = index ;
82115 fake . callbackArguments = slice ( arguments , 3 ) ;
83116 fake . callbackContext = context ;
84- fake . callArgProp = undefined ;
85- fake . callbackAsync = false ;
86117 } ,
87118
88119 usingPromise : function usingPromise ( fake , promiseLibrary ) {
89120 fake . promiseLibrary = promiseLibrary ;
90121 } ,
91122
92123 yields : function ( fake ) {
124+ clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
125+
93126 fake . callArgAt = useLeftMostCallback ;
94127 fake . callbackArguments = slice ( arguments , 1 ) ;
95- fake . callbackContext = undefined ;
96- fake . callArgProp = undefined ;
97- fake . callbackAsync = false ;
98- fake . fakeFn = undefined ;
99128 } ,
100129
101130 yieldsRight : function ( fake ) {
131+ clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
132+
102133 fake . callArgAt = useRightMostCallback ;
103134 fake . callbackArguments = slice ( arguments , 1 ) ;
104- fake . callbackContext = undefined ;
105- fake . callArgProp = undefined ;
106- fake . callbackAsync = false ;
107- fake . fakeFn = undefined ;
108135 } ,
109136
110137 yieldsOn : function ( fake , context ) {
138+ clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
139+
111140 fake . callArgAt = useLeftMostCallback ;
112141 fake . callbackArguments = slice ( arguments , 2 ) ;
113142 fake . callbackContext = context ;
114- fake . callArgProp = undefined ;
115- fake . callbackAsync = false ;
116- fake . fakeFn = undefined ;
117143 } ,
118144
119145 yieldsTo : function ( fake , prop ) {
146+ clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
147+
120148 fake . callArgAt = useLeftMostCallback ;
121149 fake . callbackArguments = slice ( arguments , 2 ) ;
122- fake . callbackContext = undefined ;
123150 fake . callArgProp = prop ;
124- fake . callbackAsync = false ;
125- fake . fakeFn = undefined ;
126151 } ,
127152
128153 yieldsToOn : function ( fake , prop , context ) {
154+ clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
155+
129156 fake . callArgAt = useLeftMostCallback ;
130157 fake . callbackArguments = slice ( arguments , 3 ) ;
131158 fake . callbackContext = context ;
132159 fake . callArgProp = prop ;
133- fake . callbackAsync = false ;
134- fake . fakeFn = undefined ;
135160 } ,
136161
137162 throws : throwsException ,
138163 throwsException : throwsException ,
139164
140165 returns : function returns ( fake , value ) {
166+ clear ( fake ) ;
167+
141168 fake . returnValue = value ;
142- fake . resolve = false ;
143- fake . reject = false ;
144169 fake . returnValueDefined = true ;
145- fake . exception = undefined ;
146- fake . exceptionCreator = undefined ;
147- fake . fakeFn = undefined ;
148170 } ,
149171
150172 returnsArg : function returnsArg ( fake , index ) {
151173 if ( typeof index !== "number" ) {
152174 throw new TypeError ( "argument index is not number" ) ;
153175 }
176+ clear ( fake ) ;
154177
155178 fake . returnArgAt = index ;
156179 } ,
@@ -159,38 +182,33 @@ const defaultBehaviors = {
159182 if ( typeof index !== "number" ) {
160183 throw new TypeError ( "argument index is not number" ) ;
161184 }
185+ clear ( fake ) ;
162186
163187 fake . throwArgAt = index ;
164188 } ,
165189
166190 returnsThis : function returnsThis ( fake ) {
191+ clear ( fake ) ;
192+
167193 fake . returnThis = true ;
168194 } ,
169195
170196 resolves : function resolves ( fake , value ) {
197+ clear ( fake ) ;
198+
171199 fake . returnValue = value ;
172200 fake . resolve = true ;
173- fake . resolveThis = false ;
174- fake . reject = false ;
175201 fake . returnValueDefined = true ;
176- fake . exception = undefined ;
177- fake . exceptionCreator = undefined ;
178- fake . fakeFn = undefined ;
179202 } ,
180203
181204 resolvesArg : function resolvesArg ( fake , index ) {
182205 if ( typeof index !== "number" ) {
183206 throw new TypeError ( "argument index is not number" ) ;
184207 }
208+ clear ( fake ) ;
209+
185210 fake . resolveArgAt = index ;
186- fake . returnValue = undefined ;
187211 fake . resolve = true ;
188- fake . resolveThis = false ;
189- fake . reject = false ;
190- fake . returnValueDefined = false ;
191- fake . exception = undefined ;
192- fake . exceptionCreator = undefined ;
193- fake . fakeFn = undefined ;
194212 } ,
195213
196214 rejects : function rejects ( fake , error , message ) {
@@ -203,34 +221,30 @@ const defaultBehaviors = {
203221 } else {
204222 reason = error ;
205223 }
224+ clear ( fake ) ;
225+
206226 fake . returnValue = reason ;
207- fake . resolve = false ;
208- fake . resolveThis = false ;
209227 fake . reject = true ;
210228 fake . returnValueDefined = true ;
211- fake . exception = undefined ;
212- fake . exceptionCreator = undefined ;
213- fake . fakeFn = undefined ;
214229
215230 return fake ;
216231 } ,
217232
218233 resolvesThis : function resolvesThis ( fake ) {
219- fake . returnValue = undefined ;
220- fake . resolve = false ;
234+ clear ( fake ) ;
235+
221236 fake . resolveThis = true ;
222- fake . reject = false ;
223- fake . returnValueDefined = false ;
224- fake . exception = undefined ;
225- fake . exceptionCreator = undefined ;
226- fake . fakeFn = undefined ;
227237 } ,
228238
229239 callThrough : function callThrough ( fake ) {
240+ clear ( fake ) ;
241+
230242 fake . callsThrough = true ;
231243 } ,
232244
233245 callThroughWithNew : function callThroughWithNew ( fake ) {
246+ clear ( fake ) ;
247+
234248 fake . callsThroughWithNew = true ;
235249 } ,
236250
0 commit comments