OLD | NEW |
---|---|
1 /** | 1 /** |
2 * @fileoverview A mock version of remoting.Xhr. Compared to | 2 * @fileoverview A mock version of remoting.Xhr. Compared to |
3 * sinon.useMockXhr, this allows unit tests to be written at a higher | 3 * sinon.useMockXhr, this allows unit tests to be written at a higher |
4 * level, and it eliminates a fair amount of boilerplate involved in | 4 * level, and it eliminates a fair amount of boilerplate involved in |
5 * making the sinon mocks work with asynchronous calls | 5 * making the sinon mocks work with asynchronous calls |
6 * (cf. gcd_client_unittest.js vs. gcd_client_with_mock_xhr.js for an | 6 * (cf. gcd_client_unittest.js vs. gcd_client_with_mock_xhr.js for an |
7 * example). | 7 * example). |
8 */ | 8 */ |
9 | 9 |
10 (function() { | 10 (function() { |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 method, urlPattern, callback, opt_reuse) { | 173 method, urlPattern, callback, opt_reuse) { |
174 handlers.push({ | 174 handlers.push({ |
175 method: method, | 175 method: method, |
176 urlPattern: urlPattern, | 176 urlPattern: urlPattern, |
177 callback: callback, | 177 callback: callback, |
178 reuse: !!opt_reuse | 178 reuse: !!opt_reuse |
179 }); | 179 }); |
180 }; | 180 }; |
181 | 181 |
182 /** | 182 /** |
183 * Calls |setResponseFor| to add a 204 (no content) response. | 183 * Calls |setResponseFor| to add a 204 (no content) response. |
Jamie
2015/04/07 01:13:12
204 is now just the default. However, it's not cle
John Williams
2015/04/07 20:10:26
I added this so I could use this method for a 500
Jamie
2015/04/08 00:16:14
Okay, but please update the comment, since it does
| |
184 * | 184 * |
185 * @param {?string} method | 185 * @param {?string} method |
186 * @param {?string|!RegExp} urlPattern | 186 * @param {?string|!RegExp} urlPattern |
187 * @param {number=} opt_status | |
187 * @param {boolean=} opt_reuse | 188 * @param {boolean=} opt_reuse |
188 */ | 189 */ |
189 remoting.MockXhr.setEmptyResponseFor = function(method, urlPattern, opt_reuse) { | 190 remoting.MockXhr.setEmptyResponseFor = function( |
191 method, urlPattern, opt_status, opt_reuse) { | |
190 remoting.MockXhr.setResponseFor( | 192 remoting.MockXhr.setResponseFor( |
191 method, urlPattern, function(/** remoting.MockXhr */ xhr) { | 193 method, urlPattern, function(/** remoting.MockXhr */ xhr) { |
192 xhr.setEmptyResponse(204); | 194 xhr.setEmptyResponse(opt_status == null ? 204 : opt_status); |
Jamie
2015/04/07 01:13:12
For the most common invocation, opt_status will be
John Williams
2015/04/07 20:10:26
In google3 I'd use goog.isDef, but here I've been
Jamie
2015/04/08 00:16:14
I guess the question here is whether or not we wan
| |
193 }, opt_reuse); | 195 }, opt_reuse); |
194 }; | 196 }; |
195 | 197 |
196 /** | 198 /** |
197 * Calls |setResponseFor| to add a 200 response with text content. | 199 * Calls |setResponseFor| to add a 200 response with text content. |
198 * | 200 * |
199 * @param {?string} method | 201 * @param {?string} method |
200 * @param {?string|!RegExp} urlPattern | 202 * @param {?string|!RegExp} urlPattern |
201 * @param {string} content | 203 * @param {string} content |
202 * @param {boolean=} opt_reuse | 204 * @param {boolean=} opt_reuse |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 // Can't put put typedefs inside a function :-( | 289 // Can't put put typedefs inside a function :-( |
288 /** | 290 /** |
289 * @typedef {{ | 291 * @typedef {{ |
290 * method:?string, | 292 * method:?string, |
291 * urlPattern:(?string|RegExp), | 293 * urlPattern:(?string|RegExp), |
292 * callback:function(!remoting.MockXhr):void, | 294 * callback:function(!remoting.MockXhr):void, |
293 * reuse:boolean | 295 * reuse:boolean |
294 * }} | 296 * }} |
295 */ | 297 */ |
296 remoting.MockXhr.UrlHandler; | 298 remoting.MockXhr.UrlHandler; |
OLD | NEW |