@@ -30,150 +30,138 @@ function throwsException(fake, error, message) {
30
30
}
31
31
}
32
32
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
-
70
33
const defaultBehaviors = {
71
34
callsFake : function callsFake ( fake , fn ) {
72
- clear ( fake ) ;
73
-
74
35
fake . fakeFn = fn ;
36
+ fake . exception = undefined ;
37
+ fake . exceptionCreator = undefined ;
38
+ fake . callsThrough = false ;
75
39
} ,
76
40
77
41
callsArg : function callsArg ( fake , index ) {
78
42
if ( typeof index !== "number" ) {
79
43
throw new TypeError ( "argument index is not number" ) ;
80
44
}
81
- clear ( fake ) ;
82
45
83
46
fake . callArgAt = index ;
84
47
fake . callbackArguments = [ ] ;
48
+ fake . callbackContext = undefined ;
49
+ fake . callArgProp = undefined ;
50
+ fake . callbackAsync = false ;
51
+ fake . callsThrough = false ;
85
52
} ,
86
53
87
54
callsArgOn : function callsArgOn ( fake , index , context ) {
88
55
if ( typeof index !== "number" ) {
89
56
throw new TypeError ( "argument index is not number" ) ;
90
57
}
91
- clear ( fake ) ;
92
58
93
59
fake . callArgAt = index ;
94
60
fake . callbackArguments = [ ] ;
95
61
fake . callbackContext = context ;
62
+ fake . callArgProp = undefined ;
63
+ fake . callbackAsync = false ;
64
+ fake . callsThrough = false ;
96
65
} ,
97
66
98
67
callsArgWith : function callsArgWith ( fake , index ) {
99
68
if ( typeof index !== "number" ) {
100
69
throw new TypeError ( "argument index is not number" ) ;
101
70
}
102
- clear ( fake ) ;
103
71
104
72
fake . callArgAt = index ;
105
73
fake . callbackArguments = slice ( arguments , 2 ) ;
74
+ fake . callbackContext = undefined ;
75
+ fake . callArgProp = undefined ;
76
+ fake . callbackAsync = false ;
77
+ fake . callsThrough = false ;
106
78
} ,
107
79
108
80
callsArgOnWith : function callsArgWith ( fake , index , context ) {
109
81
if ( typeof index !== "number" ) {
110
82
throw new TypeError ( "argument index is not number" ) ;
111
83
}
112
- clear ( fake ) ;
113
84
114
85
fake . callArgAt = index ;
115
86
fake . callbackArguments = slice ( arguments , 3 ) ;
116
87
fake . callbackContext = context ;
88
+ fake . callArgProp = undefined ;
89
+ fake . callbackAsync = false ;
90
+ fake . callsThrough = false ;
117
91
} ,
118
92
119
93
usingPromise : function usingPromise ( fake , promiseLibrary ) {
120
94
fake . promiseLibrary = promiseLibrary ;
121
95
} ,
122
96
123
97
yields : function ( fake ) {
124
- clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
125
-
126
98
fake . callArgAt = useLeftMostCallback ;
127
99
fake . callbackArguments = slice ( arguments , 1 ) ;
100
+ fake . callbackContext = undefined ;
101
+ fake . callArgProp = undefined ;
102
+ fake . callbackAsync = false ;
103
+ fake . fakeFn = undefined ;
104
+ fake . callsThrough = false ;
128
105
} ,
129
106
130
107
yieldsRight : function ( fake ) {
131
- clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
132
-
133
108
fake . callArgAt = useRightMostCallback ;
134
109
fake . callbackArguments = slice ( arguments , 1 ) ;
110
+ fake . callbackContext = undefined ;
111
+ fake . callArgProp = undefined ;
112
+ fake . callbackAsync = false ;
113
+ fake . callsThrough = false ;
114
+ fake . fakeFn = undefined ;
135
115
} ,
136
116
137
117
yieldsOn : function ( fake , context ) {
138
- clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
139
-
140
118
fake . callArgAt = useLeftMostCallback ;
141
119
fake . callbackArguments = slice ( arguments , 2 ) ;
142
120
fake . callbackContext = context ;
121
+ fake . callArgProp = undefined ;
122
+ fake . callbackAsync = false ;
123
+ fake . callsThrough = false ;
124
+ fake . fakeFn = undefined ;
143
125
} ,
144
126
145
127
yieldsTo : function ( fake , prop ) {
146
- clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
147
-
148
128
fake . callArgAt = useLeftMostCallback ;
149
129
fake . callbackArguments = slice ( arguments , 2 ) ;
130
+ fake . callbackContext = undefined ;
150
131
fake . callArgProp = prop ;
132
+ fake . callbackAsync = false ;
133
+ fake . callsThrough = false ;
134
+ fake . fakeFn = undefined ;
151
135
} ,
152
136
153
137
yieldsToOn : function ( fake , prop , context ) {
154
- clear ( fake , SKIP_OPTIONS_FOR_YIELDS ) ;
155
-
156
138
fake . callArgAt = useLeftMostCallback ;
157
139
fake . callbackArguments = slice ( arguments , 3 ) ;
158
140
fake . callbackContext = context ;
159
141
fake . callArgProp = prop ;
142
+ fake . callbackAsync = false ;
143
+ fake . fakeFn = undefined ;
160
144
} ,
161
145
162
146
throws : throwsException ,
163
147
throwsException : throwsException ,
164
148
165
149
returns : function returns ( fake , value ) {
166
- clear ( fake ) ;
167
-
150
+ fake . callsThrough = false ;
168
151
fake . returnValue = value ;
152
+ fake . resolve = false ;
153
+ fake . reject = false ;
169
154
fake . returnValueDefined = true ;
155
+ fake . exception = undefined ;
156
+ fake . exceptionCreator = undefined ;
157
+ fake . fakeFn = undefined ;
170
158
} ,
171
159
172
160
returnsArg : function returnsArg ( fake , index ) {
173
161
if ( typeof index !== "number" ) {
174
162
throw new TypeError ( "argument index is not number" ) ;
175
163
}
176
- clear ( fake ) ;
164
+ fake . callsThrough = false ;
177
165
178
166
fake . returnArgAt = index ;
179
167
} ,
@@ -182,33 +170,42 @@ const defaultBehaviors = {
182
170
if ( typeof index !== "number" ) {
183
171
throw new TypeError ( "argument index is not number" ) ;
184
172
}
185
- clear ( fake ) ;
173
+ fake . callsThrough = false ;
186
174
187
175
fake . throwArgAt = index ;
188
176
} ,
189
177
190
178
returnsThis : function returnsThis ( fake ) {
191
- clear ( fake ) ;
192
-
193
179
fake . returnThis = true ;
180
+ fake . callsThrough = false ;
194
181
} ,
195
182
196
183
resolves : function resolves ( fake , value ) {
197
- clear ( fake ) ;
198
-
199
184
fake . returnValue = value ;
200
185
fake . resolve = true ;
186
+ fake . resolveThis = false ;
187
+ fake . reject = false ;
201
188
fake . returnValueDefined = true ;
189
+ fake . exception = undefined ;
190
+ fake . exceptionCreator = undefined ;
191
+ fake . fakeFn = undefined ;
192
+ fake . callsThrough = false ;
202
193
} ,
203
194
204
195
resolvesArg : function resolvesArg ( fake , index ) {
205
196
if ( typeof index !== "number" ) {
206
197
throw new TypeError ( "argument index is not number" ) ;
207
198
}
208
- clear ( fake ) ;
209
-
210
199
fake . resolveArgAt = index ;
200
+ fake . returnValue = undefined ;
211
201
fake . resolve = true ;
202
+ fake . resolveThis = false ;
203
+ fake . reject = false ;
204
+ fake . returnValueDefined = false ;
205
+ fake . exception = undefined ;
206
+ fake . exceptionCreator = undefined ;
207
+ fake . fakeFn = undefined ;
208
+ fake . callsThrough = false ;
212
209
} ,
213
210
214
211
rejects : function rejects ( fake , error , message ) {
@@ -221,30 +218,36 @@ const defaultBehaviors = {
221
218
} else {
222
219
reason = error ;
223
220
}
224
- clear ( fake ) ;
225
-
226
221
fake . returnValue = reason ;
222
+ fake . resolve = false ;
223
+ fake . resolveThis = false ;
227
224
fake . reject = true ;
228
225
fake . returnValueDefined = true ;
226
+ fake . exception = undefined ;
227
+ fake . exceptionCreator = undefined ;
228
+ fake . fakeFn = undefined ;
229
+ fake . callsThrough = false ;
229
230
230
231
return fake ;
231
232
} ,
232
233
233
234
resolvesThis : function resolvesThis ( fake ) {
234
- clear ( fake ) ;
235
-
235
+ fake . returnValue = undefined ;
236
+ fake . resolve = false ;
236
237
fake . resolveThis = true ;
238
+ fake . reject = false ;
239
+ fake . returnValueDefined = false ;
240
+ fake . exception = undefined ;
241
+ fake . exceptionCreator = undefined ;
242
+ fake . fakeFn = undefined ;
243
+ fake . callsThrough = false ;
237
244
} ,
238
245
239
246
callThrough : function callThrough ( fake ) {
240
- clear ( fake ) ;
241
-
242
247
fake . callsThrough = true ;
243
248
} ,
244
249
245
250
callThroughWithNew : function callThroughWithNew ( fake ) {
246
- clear ( fake ) ;
247
-
248
251
fake . callsThroughWithNew = true ;
249
252
} ,
250
253
0 commit comments