| @@ -0,0 +1,3048 @@ |
| @@ -0,0 +1,3048 @@ |
| |
1
| +/* |
| |
2
| +Copyright (c) 2008-2015 Pivotal Labs |
| |
3
| + |
| |
4
| +Permission is hereby granted, free of charge, to any person obtaining |
| |
5
| +a copy of this software and associated documentation files (the |
| |
6
| +"Software"), to deal in the Software without restriction, including |
| |
7
| +without limitation the rights to use, copy, modify, merge, publish, |
| |
8
| +distribute, sublicense, and/or sell copies of the Software, and to |
| |
9
| +permit persons to whom the Software is furnished to do so, subject to |
| |
10
| +the following conditions: |
| |
11
| + |
| |
12
| +The above copyright notice and this permission notice shall be |
| |
13
| +included in all copies or substantial portions of the Software. |
| |
14
| + |
| |
15
| +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| |
16
| +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| |
17
| +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| |
18
| +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| |
19
| +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| |
20
| +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| |
21
| +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| |
22
| +*/ |
| |
23
| +var getJasmineRequireObj = (function (jasmineGlobal) { |
| |
24
| + var jasmineRequire; |
| |
25
| + |
| |
26
| + if (typeof module !== 'undefined' && module.exports) { |
| |
27
| + jasmineGlobal = global; |
| |
28
| + jasmineRequire = exports; |
| |
29
| + } else { |
| |
30
| + if (typeof window !== 'undefined' && typeof window.toString === 'function' && window.toString() === '[object GjsGlobal]') { |
| |
31
| + jasmineGlobal = window; |
| |
32
| + } |
| |
33
| + jasmineRequire = jasmineGlobal.jasmineRequire = jasmineGlobal.jasmineRequire || {}; |
| |
34
| + } |
| |
35
| + |
| |
36
| + function getJasmineRequire() { |
| |
37
| + return jasmineRequire; |
| |
38
| + } |
| |
39
| + |
| |
40
| + getJasmineRequire().core = function(jRequire) { |
| |
41
| + var j$ = {}; |
| |
42
| + |
| |
43
| + jRequire.base(j$, jasmineGlobal); |
| |
44
| + j$.util = jRequire.util(); |
| |
45
| + j$.Any = jRequire.Any(); |
| |
46
| + j$.Anything = jRequire.Anything(j$); |
| |
47
| + j$.CallTracker = jRequire.CallTracker(); |
| |
48
| + j$.MockDate = jRequire.MockDate(); |
| |
49
| + j$.Clock = jRequire.Clock(); |
| |
50
| + j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(); |
| |
51
| + j$.Env = jRequire.Env(j$); |
| |
52
| + j$.ExceptionFormatter = jRequire.ExceptionFormatter(); |
| |
53
| + j$.Expectation = jRequire.Expectation(); |
| |
54
| + j$.buildExpectationResult = jRequire.buildExpectationResult(); |
| |
55
| + j$.JsApiReporter = jRequire.JsApiReporter(); |
| |
56
| + j$.matchersUtil = jRequire.matchersUtil(j$); |
| |
57
| + j$.ObjectContaining = jRequire.ObjectContaining(j$); |
| |
58
| + j$.ArrayContaining = jRequire.ArrayContaining(j$); |
| |
59
| + j$.pp = jRequire.pp(j$); |
| |
60
| + j$.QueueRunner = jRequire.QueueRunner(j$); |
| |
61
| + j$.ReportDispatcher = jRequire.ReportDispatcher(); |
| |
62
| + j$.Spec = jRequire.Spec(j$); |
| |
63
| + j$.SpyRegistry = jRequire.SpyRegistry(j$); |
| |
64
| + j$.SpyStrategy = jRequire.SpyStrategy(); |
| |
65
| + j$.StringMatching = jRequire.StringMatching(j$); |
| |
66
| + j$.Suite = jRequire.Suite(); |
| |
67
| + j$.Timer = jRequire.Timer(); |
| |
68
| + j$.version = jRequire.version(); |
| |
69
| + |
| |
70
| + j$.matchers = jRequire.requireMatchers(jRequire, j$); |
| |
71
| + |
| |
72
| + return j$; |
| |
73
| + }; |
| |
74
| + |
| |
75
| + return getJasmineRequire; |
| |
76
| +})(this); |
| |
77
| + |
| |
78
| +getJasmineRequireObj().requireMatchers = function(jRequire, j$) { |
| |
79
| + var availableMatchers = [ |
| |
80
| + 'toBe', |
| |
81
| + 'toBeCloseTo', |
| |
82
| + 'toBeDefined', |
| |
83
| + 'toBeFalsy', |
| |
84
| + 'toBeGreaterThan', |
| |
85
| + 'toBeLessThan', |
| |
86
| + 'toBeNaN', |
| |
87
| + 'toBeNull', |
| |
88
| + 'toBeTruthy', |
| |
89
| + 'toBeUndefined', |
| |
90
| + 'toContain', |
| |
91
| + 'toEqual', |
| |
92
| + 'toHaveBeenCalled', |
| |
93
| + 'toHaveBeenCalledWith', |
| |
94
| + 'toMatch', |
| |
95
| + 'toThrow', |
| |
96
| + 'toThrowError' |
| |
97
| + ], |
| |
98
| + matchers = {}; |
| |
99
| + |
| |
100
| + for (var i = 0; i < availableMatchers.length; i++) { |
| |
101
| + var name = availableMatchers[i]; |
| |
102
| + matchers[name] = jRequire[name](j$); |
| |
103
| + } |
| |
104
| + |
| |
105
| + return matchers; |
| |
106
| +}; |
| |
107
| + |
| |
108
| +getJasmineRequireObj().base = function(j$, jasmineGlobal) { |
| |
109
| + j$.unimplementedMethod_ = function() { |
| |
110
| + throw new Error('unimplemented method'); |
| |
111
| + }; |
| |
112
| + |
| |
113
| + j$.MAX_PRETTY_PRINT_DEPTH = 40; |
| |
114
| + j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100; |
| |
115
| + j$.DEFAULT_TIMEOUT_INTERVAL = 5000; |
| |
116
| + |
| |
117
| + j$.getGlobal = function() { |
| |
118
| + return jasmineGlobal; |
| |
119
| + }; |
| |
120
| + |
| |
121
| + j$.getEnv = function(options) { |
| |
122
| + var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options); |
| |
123
| + //jasmine. singletons in here (setTimeout blah blah). |
| |
124
| + return env; |
| |
125
| + }; |
| |
126
| + |
| |
127
| + j$.isArray_ = function(value) { |
| |
128
| + return j$.isA_('Array', value); |
| |
129
| + }; |
| |
130
| + |
| |
131
| + j$.isString_ = function(value) { |
| |
132
| + return j$.isA_('String', value); |
| |
133
| + }; |
| |
134
| + |
| |
135
| + j$.isNumber_ = function(value) { |
| |
136
| + return j$.isA_('Number', value); |
| |
137
| + }; |
| |
138
| + |
| |
139
| + j$.isA_ = function(typeName, value) { |
| |
140
| + return Object.prototype.toString.apply(value) === '[object ' + typeName + ']'; |
| |
141
| + }; |
| |
142
| + |
| |
143
| + j$.isDomNode = function(obj) { |
| |
144
| + return obj.nodeType > 0; |
| |
145
| + }; |
| |
146
| + |
| |
147
| + j$.fnNameFor = function(func) { |
| |
148
| + return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1]; |
| |
149
| + }; |
| |
150
| + |
| |
151
| + j$.any = function(clazz) { |
| |
152
| + return new j$.Any(clazz); |
| |
153
| + }; |
| |
154
| + |
| |
155
| + j$.anything = function() { |
| |
156
| + return new j$.Anything(); |
| |
157
| + }; |
| |
158
| + |
| |
159
| + j$.objectContaining = function(sample) { |
| |
160
| + return new j$.ObjectContaining(sample); |
| |
161
| + }; |
| |
162
| + |
| |
163
| + j$.stringMatching = function(expected) { |
| |
164
| + return new j$.StringMatching(expected); |
| |
165
| + }; |
| |
166
| + |
| |
167
| + j$.arrayContaining = function(sample) { |
| |
168
| + return new j$.ArrayContaining(sample); |
| |
169
| + }; |
| |
170
| + |
| |
171
| + j$.createSpy = function(name, originalFn) { |
| |
172
| + |
| |
173
| + var spyStrategy = new j$.SpyStrategy({ |
| |
174
| + name: name, |
| |
175
| + fn: originalFn, |
| |
176
| + getSpy: function() { return spy; } |
| |
177
| + }), |
| |
178
| + callTracker = new j$.CallTracker(), |
| |
179
| + spy = function() { |
| |
180
| + var callData = { |
| |
181
| + object: this, |
| |
182
| + args: Array.prototype.slice.apply(arguments) |
| |
183
| + }; |
| |
184
| + |
| |
185
| + callTracker.track(callData); |
| |
186
| + var returnValue = spyStrategy.exec.apply(this, arguments); |
| |
187
| + callData.returnValue = returnValue; |
| |
188
| + |
| |
189
| + return returnValue; |
| |
190
| + }; |
| |
191
| + |
| |
192
| + for (var prop in originalFn) { |
| |
193
| + if (prop === 'and' || prop === 'calls') { |
| |
194
| + throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon'); |
| |
195
| + } |
| |
196
| + |
| |
197
| + spy[prop] = originalFn[prop]; |
| |
198
| + } |
| |
199
| + |
| |
200
| + spy.and = spyStrategy; |
| |
201
| + spy.calls = callTracker; |
| |
202
| + |
| |
203
| + return spy; |
| |
204
| + }; |
| |
205
| + |
| |
206
| + j$.isSpy = function(putativeSpy) { |
| |
207
| + if (!putativeSpy) { |
| |
208
| + return false; |
| |
209
| + } |
| |
210
| + return putativeSpy.and instanceof j$.SpyStrategy && |
| |
211
| + putativeSpy.calls instanceof j$.CallTracker; |
| |
212
| + }; |
| |
213
| + |
| |
214
| + j$.createSpyObj = function(baseName, methodNames) { |
| |
215
| + if (j$.isArray_(baseName) && j$.util.isUndefined(methodNames)) { |
| |
216
| + methodNames = baseName; |
| |
217
| + baseName = 'unknown'; |
| |
218
| + } |
| |
219
| + |
| |
220
| + if (!j$.isArray_(methodNames) || methodNames.length === 0) { |
| |
221
| + throw 'createSpyObj requires a non-empty array of method names to create spies for'; |
| |
222
| + } |
| |
223
| + var obj = {}; |
| |
224
| + for (var i = 0; i < methodNames.length; i++) { |
| |
225
| + obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]); |
| |
226
| + } |
| |
227
| + return obj; |
| |
228
| + }; |
| |
229
| +}; |
| |
230
| + |
| |
231
| +getJasmineRequireObj().util = function() { |
| |
232
| + |
| |
233
| + var util = {}; |
| |
234
| + |
| |
235
| + util.inherit = function(childClass, parentClass) { |
| |
236
| + var Subclass = function() { |
| |
237
| + }; |
| |
238
| + Subclass.prototype = parentClass.prototype; |
| |
239
| + childClass.prototype = new Subclass(); |
| |
240
| + }; |
| |
241
| + |
| |
242
| + util.htmlEscape = function(str) { |
| |
243
| + if (!str) { |
| |
244
| + return str; |
| |
245
| + } |
| |
246
| + return str.replace(/&/g, '&') |
| |
247
| + .replace(/</g, '<') |
| |
248
| + .replace(/>/g, '>'); |
| |
249
| + }; |
| |
250
| + |
| |
251
| + util.argsToArray = function(args) { |
| |
252
| + var arrayOfArgs = []; |
| |
253
| + for (var i = 0; i < args.length; i++) { |
| |
254
| + arrayOfArgs.push(args[i]); |
| |
255
| + } |
| |
256
| + return arrayOfArgs; |
| |
257
| + }; |
| |
258
| + |
| |
259
| + util.isUndefined = function(obj) { |
| |
260
| + return obj === void 0; |
| |
261
| + }; |
| |
262
| + |
| |
263
| + util.arrayContains = function(array, search) { |
| |
264
| + var i = array.length; |
| |
265
| + while (i--) { |
| |
266
| + if (array[i] === search) { |
| |
267
| + return true; |
| |
268
| + } |
| |
269
| + } |
| |
270
| + return false; |
| |
271
| + }; |
| |
272
| + |
| |
273
| + util.clone = function(obj) { |
| |
274
| + if (Object.prototype.toString.apply(obj) === '[object Array]') { |
| |
275
| + return obj.slice(); |
| |
276
| + } |
| |
277
| + |
| |
278
| + var cloned = {}; |
| |
279
| + for (var prop in obj) { |
| |
280
| + if (obj.hasOwnProperty(prop)) { |
| |
281
| + cloned[prop] = obj[prop]; |
| |
282
| + } |
| |
283
| + } |
| |
284
| + |
| |
285
| + return cloned; |
| |
286
| + }; |
| |
287
| + |
| |
288
| + return util; |
| |
289
| +}; |
| |
290
| + |
| |
291
| +getJasmineRequireObj().Spec = function(j$) { |
| |
292
| + function Spec(attrs) { |
| |
293
| + this.expectationFactory = attrs.expectationFactory; |
| |
294
| + this.resultCallback = attrs.resultCallback || function() {}; |
| |
295
| + this.id = attrs.id; |
| |
296
| + this.description = attrs.description || ''; |
| |
297
| + this.queueableFn = attrs.queueableFn; |
| |
298
| + this.beforeAndAfterFns = attrs.beforeAndAfterFns || function() { return {befores: [], afters: []}; }; |
| |
299
| + this.userContext = attrs.userContext || function() { return {}; }; |
| |
300
| + this.onStart = attrs.onStart || function() {}; |
| |
301
| + this.getSpecName = attrs.getSpecName || function() { return ''; }; |
| |
302
| + this.expectationResultFactory = attrs.expectationResultFactory || function() { }; |
| |
303
| + this.queueRunnerFactory = attrs.queueRunnerFactory || function() {}; |
| |
304
| + this.catchingExceptions = attrs.catchingExceptions || function() { return true; }; |
| |
305
| + |
| |
306
| + if (!this.queueableFn.fn) { |
| |
307
| + this.pend(); |
| |
308
| + } |
| |
309
| + |
| |
310
| + this.result = { |
| |
311
| + id: this.id, |
| |
312
| + description: this.description, |
| |
313
| + fullName: this.getFullName(), |
| |
314
| + failedExpectations: [], |
| |
315
| + passedExpectations: [], |
| |
316
| + pendingReason: '' |
| |
317
| + }; |
| |
318
| + } |
| |
319
| + |
| |
320
| + Spec.prototype.addExpectationResult = function(passed, data) { |
| |
321
| + var expectationResult = this.expectationResultFactory(data); |
| |
322
| + if (passed) { |
| |
323
| + this.result.passedExpectations.push(expectationResult); |
| |
324
| + } else { |
| |
325
| + this.result.failedExpectations.push(expectationResult); |
| |
326
| + } |
| |
327
| + }; |
| |
328
| + |
| |
329
| + Spec.prototype.expect = function(actual) { |
| |
330
| + return this.expectationFactory(actual, this); |
| |
331
| + }; |
| |
332
| + |
| |
333
| + Spec.prototype.execute = function(onComplete) { |
| |
334
| + var self = this; |
| |
335
| + |
| |
336
| + this.onStart(this); |
| |
337
| + |
| |
338
| + if (this.markedPending || this.disabled) { |
| |
339
| + complete(); |
| |
340
| + return; |
| |
341
| + } |
| |
342
| + |
| |
343
| + var fns = this.beforeAndAfterFns(); |
| |
344
| + var allFns = fns.befores.concat(this.queueableFn).concat(fns.afters); |
| |
345
| + |
| |
346
| + this.queueRunnerFactory({ |
| |
347
| + queueableFns: allFns, |
| |
348
| + onException: function() { self.onException.apply(self, arguments); }, |
| |
349
| + onComplete: complete, |
| |
350
| + userContext: this.userContext() |
| |
351
| + }); |
| |
352
| + |
| |
353
| + function complete() { |
| |
354
| + self.result.status = self.status(); |
| |
355
| + self.resultCallback(self.result); |
| |
356
| + |
| |
357
| + if (onComplete) { |
| |
358
| + onComplete(); |
| |
359
| + } |
| |
360
| + } |
| |
361
| + }; |
| |
362
| + |
| |
363
| + Spec.prototype.onException = function onException(e) { |
| |
364
| + if (Spec.isPendingSpecException(e)) { |
| |
365
| + this.pend(extractCustomPendingMessage(e)); |
| |
366
| + return; |
| |
367
| + } |
| |
368
| + |
| |
369
| + this.addExpectationResult(false, { |
| |
370
| + matcherName: '', |
| |
371
| + passed: false, |
| |
372
| + expected: '', |
| |
373
| + actual: '', |
| |
374
| + error: e |
| |
375
| + }); |
| |
376
| + }; |
| |
377
| + |
| |
378
| + Spec.prototype.disable = function() { |
| |
379
| + this.disabled = true; |
| |
380
| + }; |
| |
381
| + |
| |
382
| + Spec.prototype.pend = function(message) { |
| |
383
| + this.markedPending = true; |
| |
384
| + if (message) { |
| |
385
| + this.result.pendingReason = message; |
| |
386
| + } |
| |
387
| + }; |
| |
388
| + |
| |
389
| + Spec.prototype.status = function() { |
| |
390
| + if (this.disabled) { |
| |
391
| + return 'disabled'; |
| |
392
| + } |
| |
393
| + |
| |
394
| + if (this.markedPending) { |
| |
395
| + return 'pending'; |
| |
396
| + } |
| |
397
| + |
| |
398
| + if (this.result.failedExpectations.length > 0) { |
| |
399
| + return 'failed'; |
| |
400
| + } else { |
| |
401
| + return 'passed'; |
| |
402
| + } |
| |
403
| + }; |
| |
404
| + |
| |
405
| + Spec.prototype.isExecutable = function() { |
| |
406
| + return !this.disabled && !this.markedPending; |
| |
407
| + }; |
| |
408
| + |
| |
409
| + Spec.prototype.getFullName = function() { |
| |
410
| + return this.getSpecName(this); |
| |
411
| + }; |
| |
412
| + |
| |
413
| + var extractCustomPendingMessage = function(e) { |
| |
414
| + var fullMessage = e.toString(), |
| |
415
| + boilerplateStart = fullMessage.indexOf(Spec.pendingSpecExceptionMessage), |
| |
416
| + boilerplateEnd = boilerplateStart + Spec.pendingSpecExceptionMessage.length; |
| |
417
| + |
| |
418
| + return fullMessage.substr(boilerplateEnd); |
| |
419
| + }; |
| |
420
| + |
| |
421
| + Spec.pendingSpecExceptionMessage = '=> marked Pending'; |
| |
422
| + |
| |
423
| + Spec.isPendingSpecException = function(e) { |
| |
424
| + return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1); |
| |
425
| + }; |
| |
426
| + |
| |
427
| + return Spec; |
| |
428
| +}; |
| |
429
| + |
| |
430
| +if (typeof window == void 0 && typeof exports == 'object') { |
| |
431
| + exports.Spec = jasmineRequire.Spec; |
| |
432
| +} |
| |
433
| + |
| |
434
| +getJasmineRequireObj().Env = function(j$) { |
| |
435
| + function Env(options) { |
| |
436
| + options = options || {}; |
| |
437
| + |
| |
438
| + var self = this; |
| |
439
| + var global = options.global || j$.getGlobal(); |
| |
440
| + |
| |
441
| + var totalSpecsDefined = 0; |
| |
442
| + |
| |
443
| + var catchExceptions = true; |
| |
444
| + |
| |
445
| + var realSetTimeout = j$.getGlobal().setTimeout; |
| |
446
| + var realClearTimeout = j$.getGlobal().clearTimeout; |
| |
447
| + this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global)); |
| |
448
| + |
| |
449
| + var runnableLookupTable = {}; |
| |
450
| + var runnableResources = {}; |
| |
451
| + |
| |
452
| + var currentSpec = null; |
| |
453
| + var currentlyExecutingSuites = []; |
| |
454
| + var currentDeclarationSuite = null; |
| |
455
| + |
| |
456
| + var currentSuite = function() { |
| |
457
| + return currentlyExecutingSuites[currentlyExecutingSuites.length - 1]; |
| |
458
| + }; |
| |
459
| + |
| |
460
| + var currentRunnable = function() { |
| |
461
| + return currentSpec || currentSuite(); |
| |
462
| + }; |
| |
463
| + |
| |
464
| + var reporter = new j$.ReportDispatcher([ |
| |
465
| + 'jasmineStarted', |
| |
466
| + 'jasmineDone', |
| |
467
| + 'suiteStarted', |
| |
468
| + 'suiteDone', |
| |
469
| + 'specStarted', |
| |
470
| + 'specDone' |
| |
471
| + ]); |
| |
472
| + |
| |
473
| + this.specFilter = function() { |
| |
474
| + return true; |
| |
475
| + }; |
| |
476
| + |
| |
477
| + this.addCustomEqualityTester = function(tester) { |
| |
478
| + if(!currentRunnable()) { |
| |
479
| + throw new Error('Custom Equalities must be added in a before function or a spec'); |
| |
480
| + } |
| |
481
| + runnableResources[currentRunnable().id].customEqualityTesters.push(tester); |
| |
482
| + }; |
| |
483
| + |
| |
484
| + this.addMatchers = function(matchersToAdd) { |
| |
485
| + if(!currentRunnable()) { |
| |
486
| + throw new Error('Matchers must be added in a before function or a spec'); |
| |
487
| + } |
| |
488
| + var customMatchers = runnableResources[currentRunnable().id].customMatchers; |
| |
489
| + for (var matcherName in matchersToAdd) { |
| |
490
| + customMatchers[matcherName] = matchersToAdd[matcherName]; |
| |
491
| + } |
| |
492
| + }; |
| |
493
| + |
| |
494
| + j$.Expectation.addCoreMatchers(j$.matchers); |
| |
495
| + |
| |
496
| + var nextSpecId = 0; |
| |
497
| + var getNextSpecId = function() { |
| |
498
| + return 'spec' + nextSpecId++; |
| |
499
| + }; |
| |
500
| + |
| |
501
| + var nextSuiteId = 0; |
| |
502
| + var getNextSuiteId = function() { |
| |
503
| + return 'suite' + nextSuiteId++; |
| |
504
| + }; |
| |
505
| + |
| |
506
| + var expectationFactory = function(actual, spec) { |
| |
507
| + return j$.Expectation.Factory({ |
| |
508
| + util: j$.matchersUtil, |
| |
509
| + customEqualityTesters: runnableResources[spec.id].customEqualityTesters, |
| |
510
| + customMatchers: runnableResources[spec.id].customMatchers, |
| |
511
| + actual: actual, |
| |
512
| + addExpectationResult: addExpectationResult |
| |
513
| + }); |
| |
514
| + |
| |
515
| + function addExpectationResult(passed, result) { |
| |
516
| + return spec.addExpectationResult(passed, result); |
| |
517
| + } |
| |
518
| + }; |
| |
519
| + |
| |
520
| + var defaultResourcesForRunnable = function(id, parentRunnableId) { |
| |
521
| + var resources = {spies: [], customEqualityTesters: [], customMatchers: {}}; |
| |
522
| + |
| |
523
| + if(runnableResources[parentRunnableId]){ |
| |
524
| + resources.customEqualityTesters = j$.util.clone(runnableResources[parentRunnableId].customEqualityTesters); |
| |
525
| + resources.customMatchers = j$.util.clone(runnableResources[parentRunnableId].customMatchers); |
| |
526
| + } |
| |
527
| + |
| |
528
| + runnableResources[id] = resources; |
| |
529
| + }; |
| |
530
| + |
| |
531
| + var clearResourcesForRunnable = function(id) { |
| |
532
| + spyRegistry.clearSpies(); |
| |
533
| + delete runnableResources[id]; |
| |
534
| + }; |
| |
535
| + |
| |
536
| + var beforeAndAfterFns = function(suite, runnablesExplictlySet) { |
| |
537
| + return function() { |
| |
538
| + var befores = [], |
| |
539
| + afters = [], |
| |
540
| + beforeAlls = [], |
| |
541
| + afterAlls = []; |
| |
542
| + |
| |
543
| + while(suite) { |
| |
544
| + befores = befores.concat(suite.beforeFns); |
| |
545
| + afters = afters.concat(suite.afterFns); |
| |
546
| + |
| |
547
| + if (runnablesExplictlySet()) { |
| |
548
| + beforeAlls = beforeAlls.concat(suite.beforeAllFns); |
| |
549
| + afterAlls = afterAlls.concat(suite.afterAllFns); |
| |
550
| + } |
| |
551
| + |
| |
552
| + suite = suite.parentSuite; |
| |
553
| + } |
| |
554
| + return { |
| |
555
| + befores: beforeAlls.reverse().concat(befores.reverse()), |
| |
556
| + afters: afters.concat(afterAlls) |
| |
557
| + }; |
| |
558
| + }; |
| |
559
| + }; |
| |
560
| + |
| |
561
| + var getSpecName = function(spec, suite) { |
| |
562
| + return suite.getFullName() + ' ' + spec.description; |
| |
563
| + }; |
| |
564
| + |
| |
565
| + // TODO: we may just be able to pass in the fn instead of wrapping here |
| |
566
| + var buildExpectationResult = j$.buildExpectationResult, |
| |
567
| + exceptionFormatter = new j$.ExceptionFormatter(), |
| |
568
| + expectationResultFactory = function(attrs) { |
| |
569
| + attrs.messageFormatter = exceptionFormatter.message; |
| |
570
| + attrs.stackFormatter = exceptionFormatter.stack; |
| |
571
| + |
| |
572
| + return buildExpectationResult(attrs); |
| |
573
| + }; |
| |
574
| + |
| |
575
| + // TODO: fix this naming, and here's where the value comes in |
| |
576
| + this.catchExceptions = function(value) { |
| |
577
| + catchExceptions = !!value; |
| |
578
| + return catchExceptions; |
| |
579
| + }; |
| |
580
| + |
| |
581
| + this.catchingExceptions = function() { |
| |
582
| + return catchExceptions; |
| |
583
| + }; |
| |
584
| + |
| |
585
| + var maximumSpecCallbackDepth = 20; |
| |
586
| + var currentSpecCallbackDepth = 0; |
| |
587
| + |
| |
588
| + function clearStack(fn) { |
| |
589
| + currentSpecCallbackDepth++; |
| |
590
| + if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) { |
| |
591
| + currentSpecCallbackDepth = 0; |
| |
592
| + realSetTimeout(fn, 0); |
| |
593
| + } else { |
| |
594
| + fn(); |
| |
595
| + } |
| |
596
| + } |
| |
597
| + |
| |
598
| + var catchException = function(e) { |
| |
599
| + return j$.Spec.isPendingSpecException(e) || catchExceptions; |
| |
600
| + }; |
| |
601
| + |
| |
602
| + var queueRunnerFactory = function(options) { |
| |
603
| + options.catchException = catchException; |
| |
604
| + options.clearStack = options.clearStack || clearStack; |
| |
605
| + options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout}; |
| |
606
| + options.fail = self.fail; |
| |
607
| + |
| |
608
| + new j$.QueueRunner(options).execute(); |
| |
609
| + }; |
| |
610
| + |
| |
611
| + var topSuite = new j$.Suite({ |
| |
612
| + env: this, |
| |
613
| + id: getNextSuiteId(), |
| |
614
| + description: 'Jasmine__TopLevel__Suite', |
| |
615
| + queueRunner: queueRunnerFactory |
| |
616
| + }); |
| |
617
| + runnableLookupTable[topSuite.id] = topSuite; |
| |
618
| + defaultResourcesForRunnable(topSuite.id); |
| |
619
| + currentDeclarationSuite = topSuite; |
| |
620
| + |
| |
621
| + this.topSuite = function() { |
| |
622
| + return topSuite; |
| |
623
| + }; |
| |
624
| + |
| |
625
| + this.execute = function(runnablesToRun) { |
| |
626
| + if(runnablesToRun) { |
| |
627
| + runnablesExplictlySet = true; |
| |
628
| + } else if (focusedRunnables.length) { |
| |
629
| + runnablesExplictlySet = true; |
| |
630
| + runnablesToRun = focusedRunnables; |
| |
631
| + } else { |
| |
632
| + runnablesToRun = [topSuite.id]; |
| |
633
| + } |
| |
634
| + |
| |
635
| + var allFns = []; |
| |
636
| + for(var i = 0; i < runnablesToRun.length; i++) { |
| |
637
| + var runnable = runnableLookupTable[runnablesToRun[i]]; |
| |
638
| + allFns.push((function(runnable) { return { fn: function(done) { runnable.execute(done); } }; })(runnable)); |
| |
639
| + } |
| |
640
| + |
| |
641
| + reporter.jasmineStarted({ |
| |
642
| + totalSpecsDefined: totalSpecsDefined |
| |
643
| + }); |
| |
644
| + |
| |
645
| + queueRunnerFactory({queueableFns: allFns, onComplete: reporter.jasmineDone}); |
| |
646
| + }; |
| |
647
| + |
| |
648
| + this.addReporter = function(reporterToAdd) { |
| |
649
| + reporter.addReporter(reporterToAdd); |
| |
650
| + }; |
| |
651
| + |
| |
652
| + var spyRegistry = new j$.SpyRegistry({currentSpies: function() { |
| |
653
| + if(!currentRunnable()) { |
| |
654
| + throw new Error('Spies must be created in a before function or a spec'); |
| |
655
| + } |
| |
656
| + return runnableResources[currentRunnable().id].spies; |
| |
657
| + }}); |
| |
658
| + |
| |
659
| + this.spyOn = function() { |
| |
660
| + return spyRegistry.spyOn.apply(spyRegistry, arguments); |
| |
661
| + }; |
| |
662
| + |
| |
663
| + var suiteFactory = function(description) { |
| |
664
| + var suite = new j$.Suite({ |
| |
665
| + env: self, |
| |
666
| + id: getNextSuiteId(), |
| |
667
| + description: description, |
| |
668
| + parentSuite: currentDeclarationSuite, |
| |
669
| + queueRunner: queueRunnerFactory, |
| |
670
| + onStart: suiteStarted, |
| |
671
| + expectationFactory: expectationFactory, |
| |
672
| + expectationResultFactory: expectationResultFactory, |
| |
673
| + runnablesExplictlySetGetter: runnablesExplictlySetGetter, |
| |
674
| + resultCallback: function(attrs) { |
| |
675
| + if (!suite.disabled) { |
| |
676
| + clearResourcesForRunnable(suite.id); |
| |
677
| + } |
| |
678
| + currentlyExecutingSuites.pop(); |
| |
679
| + reporter.suiteDone(attrs); |
| |
680
| + } |
| |
681
| + }); |
| |
682
| + |
| |
683
| + runnableLookupTable[suite.id] = suite; |
| |
684
| + return suite; |
| |
685
| + |
| |
686
| + function suiteStarted(suite) { |
| |
687
| + currentlyExecutingSuites.push(suite); |
| |
688
| + defaultResourcesForRunnable(suite.id, suite.parentSuite.id); |
| |
689
| + reporter.suiteStarted(suite.result); |
| |
690
| + } |
| |
691
| + }; |
| |
692
| + |
| |
693
| + this.describe = function(description, specDefinitions) { |
| |
694
| + var suite = suiteFactory(description); |
| |
695
| + addSpecsToSuite(suite, specDefinitions); |
| |
696
| + return suite; |
| |
697
| + }; |
| |
698
| + |
| |
699
| + this.xdescribe = function(description, specDefinitions) { |
| |
700
| + var suite = this.describe(description, specDefinitions); |
| |
701
| + suite.disable(); |
| |
702
| + return suite; |
| |
703
| + }; |
| |
704
| + |
| |
705
| + var focusedRunnables = []; |
| |
706
| + |
| |
707
| + this.fdescribe = function(description, specDefinitions) { |
| |
708
| + var suite = suiteFactory(description); |
| |
709
| + suite.isFocused = true; |
| |
710
| + |
| |
711
| + focusedRunnables.push(suite.id); |
| |
712
| + unfocusAncestor(); |
| |
713
| + addSpecsToSuite(suite, specDefinitions); |
| |
714
| + |
| |
715
| + return suite; |
| |
716
| + }; |
| |
717
| + |
| |
718
| + function addSpecsToSuite(suite, specDefinitions) { |
| |
719
| + var parentSuite = currentDeclarationSuite; |
| |
720
| + parentSuite.addChild(suite); |
| |
721
| + currentDeclarationSuite = suite; |
| |
722
| + |
| |
723
| + var declarationError = null; |
| |
724
| + try { |
| |
725
| + specDefinitions.call(suite); |
| |
726
| + } catch (e) { |
| |
727
| + declarationError = e; |
| |
728
| + } |
| |
729
| + |
| |
730
| + if (declarationError) { |
| |
731
| + self.it('encountered a declaration exception', function() { |
| |
732
| + throw declarationError; |
| |
733
| + }); |
| |
734
| + } |
| |
735
| + |
| |
736
| + currentDeclarationSuite = parentSuite; |
| |
737
| + } |
| |
738
| + |
| |
739
| + function findFocusedAncestor(suite) { |
| |
740
| + while (suite) { |
| |
741
| + if (suite.isFocused) { |
| |
742
| + return suite.id; |
| |
743
| + } |
| |
744
| + suite = suite.parentSuite; |
| |
745
| + } |
| |
746
| + |
| |
747
| + return null; |
| |
748
| + } |
| |
749
| + |
| |
750
| + function unfocusAncestor() { |
| |
751
| + var focusedAncestor = findFocusedAncestor(currentDeclarationSuite); |
| |
752
| + if (focusedAncestor) { |
| |
753
| + for (var i = 0; i < focusedRunnables.length; i++) { |
| |
754
| + if (focusedRunnables[i] === focusedAncestor) { |
| |
755
| + focusedRunnables.splice(i, 1); |
| |
756
| + break; |
| |
757
| + } |
| |
758
| + } |
| |
759
| + } |
| |
760
| + } |
| |
761
| + |
| |
762
| + var runnablesExplictlySet = false; |
| |
763
| + |
| |
764
| + var runnablesExplictlySetGetter = function(){ |
| |
765
| + return runnablesExplictlySet; |
| |
766
| + }; |
| |
767
| + |
| |
768
| + var specFactory = function(description, fn, suite, timeout) { |
| |
769
| + totalSpecsDefined++; |
| |
770
| + var spec = new j$.Spec({ |
| |
771
| + id: getNextSpecId(), |
| |
772
| + beforeAndAfterFns: beforeAndAfterFns(suite, runnablesExplictlySetGetter), |
| |
773
| + expectationFactory: expectationFactory, |
| |
774
| + resultCallback: specResultCallback, |
| |
775
| + getSpecName: function(spec) { |
| |
776
| + return getSpecName(spec, suite); |
| |
777
| + }, |
| |
778
| + onStart: specStarted, |
| |
779
| + description: description, |
| |
780
| + expectationResultFactory: expectationResultFactory, |
| |
781
| + queueRunnerFactory: queueRunnerFactory, |
| |
782
| + userContext: function() { return suite.clonedSharedUserContext(); }, |
| |
783
| + queueableFn: { |
| |
784
| + fn: fn, |
| |
785
| + timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } |
| |
786
| + } |
| |
787
| + }); |
| |
788
| + |
| |
789
| + runnableLookupTable[spec.id] = spec; |
| |
790
| + |
| |
791
| + if (!self.specFilter(spec)) { |
| |
792
| + spec.disable(); |
| |
793
| + } |
| |
794
| + |
| |
795
| + return spec; |
| |
796
| + |
| |
797
| + function specResultCallback(result) { |
| |
798
| + clearResourcesForRunnable(spec.id); |
| |
799
| + currentSpec = null; |
| |
800
| + reporter.specDone(result); |
| |
801
| + } |
| |
802
| + |
| |
803
| + function specStarted(spec) { |
| |
804
| + currentSpec = spec; |
| |
805
| + defaultResourcesForRunnable(spec.id, suite.id); |
| |
806
| + reporter.specStarted(spec.result); |
| |
807
| + } |
| |
808
| + }; |
| |
809
| + |
| |
810
| + this.it = function(description, fn, timeout) { |
| |
811
| + var spec = specFactory(description, fn, currentDeclarationSuite, timeout); |
| |
812
| + currentDeclarationSuite.addChild(spec); |
| |
813
| + return spec; |
| |
814
| + }; |
| |
815
| + |
| |
816
| + this.xit = function() { |
| |
817
| + var spec = this.it.apply(this, arguments); |
| |
818
| + spec.pend(); |
| |
819
| + return spec; |
| |
820
| + }; |
| |
821
| + |
| |
822
| + this.fit = function(){ |
| |
823
| + var spec = this.it.apply(this, arguments); |
| |
824
| + |
| |
825
| + focusedRunnables.push(spec.id); |
| |
826
| + unfocusAncestor(); |
| |
827
| + return spec; |
| |
828
| + }; |
| |
829
| + |
| |
830
| + this.expect = function(actual) { |
| |
831
| + if (!currentRunnable()) { |
| |
832
| + throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out'); |
| |
833
| + } |
| |
834
| + |
| |
835
| + return currentRunnable().expect(actual); |
| |
836
| + }; |
| |
837
| + |
| |
838
| + this.beforeEach = function(beforeEachFunction, timeout) { |
| |
839
| + currentDeclarationSuite.beforeEach({ |
| |
840
| + fn: beforeEachFunction, |
| |
841
| + timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } |
| |
842
| + }); |
| |
843
| + }; |
| |
844
| + |
| |
845
| + this.beforeAll = function(beforeAllFunction, timeout) { |
| |
846
| + currentDeclarationSuite.beforeAll({ |
| |
847
| + fn: beforeAllFunction, |
| |
848
| + timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } |
| |
849
| + }); |
| |
850
| + }; |
| |
851
| + |
| |
852
| + this.afterEach = function(afterEachFunction, timeout) { |
| |
853
| + currentDeclarationSuite.afterEach({ |
| |
854
| + fn: afterEachFunction, |
| |
855
| + timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } |
| |
856
| + }); |
| |
857
| + }; |
| |
858
| + |
| |
859
| + this.afterAll = function(afterAllFunction, timeout) { |
| |
860
| + currentDeclarationSuite.afterAll({ |
| |
861
| + fn: afterAllFunction, |
| |
862
| + timeout: function() { return timeout || j$.DEFAULT_TIMEOUT_INTERVAL; } |
| |
863
| + }); |
| |
864
| + }; |
| |
865
| + |
| |
866
| + this.pending = function(message) { |
| |
867
| + var fullMessage = j$.Spec.pendingSpecExceptionMessage; |
| |
868
| + if(message) { |
| |
869
| + fullMessage += message; |
| |
870
| + } |
| |
871
| + throw fullMessage; |
| |
872
| + }; |
| |
873
| + |
| |
874
| + this.fail = function(error) { |
| |
875
| + var message = 'Failed'; |
| |
876
| + if (error) { |
| |
877
| + message += ': '; |
| |
878
| + message += error.message || error; |
| |
879
| + } |
| |
880
| + |
| |
881
| + currentRunnable().addExpectationResult(false, { |
| |
882
| + matcherName: '', |
| |
883
| + passed: false, |
| |
884
| + expected: '', |
| |
885
| + actual: '', |
| |
886
| + message: message, |
| |
887
| + error: error && error.message ? error : null |
| |
888
| + }); |
| |
889
| + }; |
| |
890
| + } |
| |
891
| + |
| |
892
| + return Env; |
| |
893
| +}; |
| |
894
| + |
| |
895
| +getJasmineRequireObj().JsApiReporter = function() { |
| |
896
| + |
| |
897
| + var noopTimer = { |
| |
898
| + start: function(){}, |
| |
899
| + elapsed: function(){ return 0; } |
| |
900
| + }; |
| |
901
| + |
| |
902
| + function JsApiReporter(options) { |
| |
903
| + var timer = options.timer || noopTimer, |
| |
904
| + status = 'loaded'; |
| |
905
| + |
| |
906
| + this.started = false; |
| |
907
| + this.finished = false; |
| |
908
| + |
| |
909
| + this.jasmineStarted = function() { |
| |
910
| + this.started = true; |
| |
911
| + status = 'started'; |
| |
912
| + timer.start(); |
| |
913
| + }; |
| |
914
| + |
| |
915
| + var executionTime; |
| |
916
| + |
| |
917
| + this.jasmineDone = function() { |
| |
918
| + this.finished = true; |
| |
919
| + executionTime = timer.elapsed(); |
| |
920
| + status = 'done'; |
| |
921
| + }; |
| |
922
| + |
| |
923
| + this.status = function() { |
| |
924
| + return status; |
| |
925
| + }; |
| |
926
| + |
| |
927
| + var suites = [], |
| |
928
| + suites_hash = {}; |
| |
929
| + |
| |
930
| + this.suiteStarted = function(result) { |
| |
931
| + suites_hash[result.id] = result; |
| |
932
| + }; |
| |
933
| + |
| |
934
| + this.suiteDone = function(result) { |
| |
935
| + storeSuite(result); |
| |
936
| + }; |
| |
937
| + |
| |
938
| + this.suiteResults = function(index, length) { |
| |
939
| + return suites.slice(index, index + length); |
| |
940
| + }; |
| |
941
| + |
| |
942
| + function storeSuite(result) { |
| |
943
| + suites.push(result); |
| |
944
| + suites_hash[result.id] = result; |
| |
945
| + } |
| |
946
| + |
| |
947
| + this.suites = function() { |
| |
948
| + return suites_hash; |
| |
949
| + }; |
| |
950
| + |
| |
951
| + var specs = []; |
| |
952
| + |
| |
953
| + this.specDone = function(result) { |
| |
954
| + specs.push(result); |
| |
955
| + }; |
| |
956
| + |
| |
957
| + this.specResults = function(index, length) { |
| |
958
| + return specs.slice(index, index + length); |
| |
959
| + }; |
| |
960
| + |
| |
961
| + this.specs = function() { |
| |
962
| + return specs; |
| |
963
| + }; |
| |
964
| + |
| |
965
| + this.executionTime = function() { |
| |
966
| + return executionTime; |
| |
967
| + }; |
| |
968
| + |
| |
969
| + } |
| |
970
| + |
| |
971
| + return JsApiReporter; |
| |
972
| +}; |
| |
973
| + |
| |
974
| +getJasmineRequireObj().CallTracker = function() { |
| |
975
| + |
| |
976
| + function CallTracker() { |
| |
977
| + var calls = []; |
| |
978
| + |
| |
979
| + this.track = function(context) { |
| |
980
| + calls.push(context); |
| |
981
| + }; |
| |
982
| + |
| |
983
| + this.any = function() { |
| |
984
| + return !!calls.length; |
| |
985
| + }; |
| |
986
| + |
| |
987
| + this.count = function() { |
| |
988
| + return calls.length; |
| |
989
| + }; |
| |
990
| + |
| |
991
| + this.argsFor = function(index) { |
| |
992
| + var call = calls[index]; |
| |
993
| + return call ? call.args : []; |
| |
994
| + }; |
| |
995
| + |
| |
996
| + this.all = function() { |
| |
997
| + return calls; |
| |
998
| + }; |
| |
999
| + |
| |
1000
| + this.allArgs = function() { |
| |
1001
| + var callArgs = []; |
| |
1002
| + for(var i = 0; i < calls.length; i++){ |
| |
1003
| + callArgs.push(calls[i].args); |
| |
1004
| + } |
| |
1005
| + |
| |
1006
| + return callArgs; |
| |
1007
| + }; |
| |
1008
| + |
| |
1009
| + this.first = function() { |
| |
1010
| + return calls[0]; |
| |
1011
| + }; |
| |
1012
| + |
| |
1013
| + this.mostRecent = function() { |
| |
1014
| + return calls[calls.length - 1]; |
| |
1015
| + }; |
| |
1016
| + |
| |
1017
| + this.reset = function() { |
| |
1018
| + calls = []; |
| |
1019
| + }; |
| |
1020
| + } |
| |
1021
| + |
| |
1022
| + return CallTracker; |
| |
1023
| +}; |
| |
1024
| + |
| |
1025
| +getJasmineRequireObj().Clock = function() { |
| |
1026
| + function Clock(global, delayedFunctionScheduler, mockDate) { |
| |
1027
| + var self = this, |
| |
1028
| + realTimingFunctions = { |
| |
1029
| + setTimeout: global.setTimeout, |
| |
1030
| + clearTimeout: global.clearTimeout, |
| |
1031
| + setInterval: global.setInterval, |
| |
1032
| + clearInterval: global.clearInterval |
| |
1033
| + }, |
| |
1034
| + fakeTimingFunctions = { |
| |
1035
| + setTimeout: setTimeout, |
| |
1036
| + clearTimeout: clearTimeout, |
| |
1037
| + setInterval: setInterval, |
| |
1038
| + clearInterval: clearInterval |
| |
1039
| + }, |
| |
1040
| + installed = false, |
| |
1041
| + timer; |
| |
1042
| + |
| |
1043
| + |
| |
1044
| + self.install = function() { |
| |
1045
| + replace(global, fakeTimingFunctions); |
| |
1046
| + timer = fakeTimingFunctions; |
| |
1047
| + installed = true; |
| |
1048
| + |
| |
1049
| + return self; |
| |
1050
| + }; |
| |
1051
| + |
| |
1052
| + self.uninstall = function() { |
| |
1053
| + delayedFunctionScheduler.reset(); |
| |
1054
| + mockDate.uninstall(); |
| |
1055
| + replace(global, realTimingFunctions); |
| |
1056
| + |
| |
1057
| + timer = realTimingFunctions; |
| |
1058
| + installed = false; |
| |
1059
| + }; |
| |
1060
| + |
| |
1061
| + self.mockDate = function(initialDate) { |
| |
1062
| + mockDate.install(initialDate); |
| |
1063
| + }; |
| |
1064
| + |
| |
1065
| + self.setTimeout = function(fn, delay, params) { |
| |
1066
| + if (legacyIE()) { |
| |
1067
| + if (arguments.length > 2) { |
| |
1068
| + throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill'); |
| |
1069
| + } |
| |
1070
| + return timer.setTimeout(fn, delay); |
| |
1071
| + } |
| |
1072
| + return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]); |
| |
1073
| + }; |
| |
1074
| + |
| |
1075
| + self.setInterval = function(fn, delay, params) { |
| |
1076
| + if (legacyIE()) { |
| |
1077
| + if (arguments.length > 2) { |
| |
1078
| + throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill'); |
| |
1079
| + } |
| |
1080
| + return timer.setInterval(fn, delay); |
| |
1081
| + } |
| |
1082
| + return Function.prototype.apply.apply(timer.setInterval, [global, arguments]); |
| |
1083
| + }; |
| |
1084
| + |
| |
1085
| + self.clearTimeout = function(id) { |
| |
1086
| + return Function.prototype.call.apply(timer.clearTimeout, [global, id]); |
| |
1087
| + }; |
| |
1088
| + |
| |
1089
| + self.clearInterval = function(id) { |
| |
1090
| + return Function.prototype.call.apply(timer.clearInterval, [global, id]); |
| |
1091
| + }; |
| |
1092
| + |
| |
1093
| + self.tick = function(millis) { |
| |
1094
| + if (installed) { |
| |
1095
| + mockDate.tick(millis); |
| |
1096
| + delayedFunctionScheduler.tick(millis); |
| |
1097
| + } else { |
| |
1098
| + throw new Error('Mock clock is not installed, use jasmine.clock().install()'); |
| |
1099
| + } |
| |
1100
| + }; |
| |
1101
| + |
| |
1102
| + return self; |
| |
1103
| + |
| |
1104
| + function legacyIE() { |
| |
1105
| + //if these methods are polyfilled, apply will be present |
| |
1106
| + return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply; |
| |
1107
| + } |
| |
1108
| + |
| |
1109
| + function replace(dest, source) { |
| |
1110
| + for (var prop in source) { |
| |
1111
| + dest[prop] = source[prop]; |
| |
1112
| + } |
| |
1113
| + } |
| |
1114
| + |
| |
1115
| + function setTimeout(fn, delay) { |
| |
1116
| + return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2)); |
| |
1117
| + } |
| |
1118
| + |
| |
1119
| + function clearTimeout(id) { |
| |
1120
| + return delayedFunctionScheduler.removeFunctionWithId(id); |
| |
1121
| + } |
| |
1122
| + |
| |
1123
| + function setInterval(fn, interval) { |
| |
1124
| + return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true); |
| |
1125
| + } |
| |
1126
| + |
| |
1127
| + function clearInterval(id) { |
| |
1128
| + return delayedFunctionScheduler.removeFunctionWithId(id); |
| |
1129
| + } |
| |
1130
| + |
| |
1131
| + function argSlice(argsObj, n) { |
| |
1132
| + return Array.prototype.slice.call(argsObj, n); |
| |
1133
| + } |
| |
1134
| + } |
| |
1135
| + |
| |
1136
| + return Clock; |
| |
1137
| +}; |
| |
1138
| + |
| |
1139
| +getJasmineRequireObj().DelayedFunctionScheduler = function() { |
| |
1140
| + function DelayedFunctionScheduler() { |
| |
1141
| + var self = this; |
| |
1142
| + var scheduledLookup = []; |
| |
1143
| + var scheduledFunctions = {}; |
| |
1144
| + var currentTime = 0; |
| |
1145
| + var delayedFnCount = 0; |
| |
1146
| + |
| |
1147
| + self.tick = function(millis) { |
| |
1148
| + millis = millis || 0; |
| |
1149
| + var endTime = currentTime + millis; |
| |
1150
| + |
| |
1151
| + runScheduledFunctions(endTime); |
| |
1152
| + currentTime = endTime; |
| |
1153
| + }; |
| |
1154
| + |
| |
1155
| + self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) { |
| |
1156
| + var f; |
| |
1157
| + if (typeof(funcToCall) === 'string') { |
| |
1158
| + /* jshint evil: true */ |
| |
1159
| + f = function() { return eval(funcToCall); }; |
| |
1160
| + /* jshint evil: false */ |
| |
1161
| + } else { |
| |
1162
| + f = funcToCall; |
| |
1163
| + } |
| |
1164
| + |
| |
1165
| + millis = millis || 0; |
| |
1166
| + timeoutKey = timeoutKey || ++delayedFnCount; |
| |
1167
| + runAtMillis = runAtMillis || (currentTime + millis); |
| |
1168
| + |
| |
1169
| + var funcToSchedule = { |
| |
1170
| + runAtMillis: runAtMillis, |
| |
1171
| + funcToCall: f, |
| |
1172
| + recurring: recurring, |
| |
1173
| + params: params, |
| |
1174
| + timeoutKey: timeoutKey, |
| |
1175
| + millis: millis |
| |
1176
| + }; |
| |
1177
| + |
| |
1178
| + if (runAtMillis in scheduledFunctions) { |
| |
1179
| + scheduledFunctions[runAtMillis].push(funcToSchedule); |
| |
1180
| + } else { |
| |
1181
| + scheduledFunctions[runAtMillis] = [funcToSchedule]; |
| |
1182
| + scheduledLookup.push(runAtMillis); |
| |
1183
| + scheduledLookup.sort(function (a, b) { |
| |
1184
| + return a - b; |
| |
1185
| + }); |
| |
1186
| + } |
| |
1187
| + |
| |
1188
| + return timeoutKey; |
| |
1189
| + }; |
| |
1190
| + |
| |
1191
| + self.removeFunctionWithId = function(timeoutKey) { |
| |
1192
| + for (var runAtMillis in scheduledFunctions) { |
| |
1193
| + var funcs = scheduledFunctions[runAtMillis]; |
| |
1194
| + var i = indexOfFirstToPass(funcs, function (func) { |
| |
1195
| + return func.timeoutKey === timeoutKey; |
| |
1196
| + }); |
| |
1197
| + |
| |
1198
| + if (i > -1) { |
| |
1199
| + if (funcs.length === 1) { |
| |
1200
| + delete scheduledFunctions[runAtMillis]; |
| |
1201
| + deleteFromLookup(runAtMillis); |
| |
1202
| + } else { |
| |
1203
| + funcs.splice(i, 1); |
| |
1204
| + } |
| |
1205
| + |
| |
1206
| + // intervals get rescheduled when executed, so there's never more |
| |
1207
| + // than a single scheduled function with a given timeoutKey |
| |
1208
| + break; |
| |
1209
| + } |
| |
1210
| + } |
| |
1211
| + }; |
| |
1212
| + |
| |
1213
| + self.reset = function() { |
| |
1214
| + currentTime = 0; |
| |
1215
| + scheduledLookup = []; |
| |
1216
| + scheduledFunctions = {}; |
| |
1217
| + delayedFnCount = 0; |
| |
1218
| + }; |
| |
1219
| + |
| |
1220
| + return self; |
| |
1221
| + |
| |
1222
| + function indexOfFirstToPass(array, testFn) { |
| |
1223
| + var index = -1; |
| |
1224
| + |
| |
1225
| + for (var i = 0; i < array.length; ++i) { |
| |
1226
| + if (testFn(array[i])) { |
| |
1227
| + index = i; |
| |
1228
| + break; |
| |
1229
| + } |
| |
1230
| + } |
| |
1231
| + |
| |
1232
| + return index; |
| |
1233
| + } |
| |
1234
| + |
| |
1235
| + function deleteFromLookup(key) { |
| |
1236
| + var value = Number(key); |
| |
1237
| + var i = indexOfFirstToPass(scheduledLookup, function (millis) { |
| |
1238
| + return millis === value; |
| |
1239
| + }); |
| |
1240
| + |
| |
1241
| + if (i > -1) { |
| |
1242
| + scheduledLookup.splice(i, 1); |
| |
1243
| + } |
| |
1244
| + } |
| |
1245
| + |
| |
1246
| + function reschedule(scheduledFn) { |
| |
1247
| + self.scheduleFunction(scheduledFn.funcToCall, |
| |
1248
| + scheduledFn.millis, |
| |
1249
| + scheduledFn.params, |
| |
1250
| + true, |
| |
1251
| + scheduledFn.timeoutKey, |
| |
1252
| + scheduledFn.runAtMillis + scheduledFn.millis); |
| |
1253
| + } |
| |
1254
| + |
| |
1255
| + function forEachFunction(funcsToRun, callback) { |
| |
1256
| + for (var i = 0; i < funcsToRun.length; ++i) { |
| |
1257
| + callback(funcsToRun[i]); |
| |
1258
| + } |
| |
1259
| + } |
| |
1260
| + |
| |
1261
| + function runScheduledFunctions(endTime) { |
| |
1262
| + if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) { |
| |
1263
| + return; |
| |
1264
| + } |
| |
1265
| + |
| |
1266
| + do { |
| |
1267
| + currentTime = scheduledLookup.shift(); |
| |
1268
| + |
| |
1269
| + var funcsToRun = scheduledFunctions[currentTime]; |
| |
1270
| + delete scheduledFunctions[currentTime]; |
| |
1271
| + |
| |
1272
| + forEachFunction(funcsToRun, function(funcToRun) { |
| |
1273
| + if (funcToRun.recurring) { |
| |
1274
| + reschedule(funcToRun); |
| |
1275
| + } |
| |
1276
| + }); |
| |
1277
| + |
| |
1278
| + forEachFunction(funcsToRun, function(funcToRun) { |
| |
1279
| + funcToRun.funcToCall.apply(null, funcToRun.params || []); |
| |
1280
| + }); |
| |
1281
| + } while (scheduledLookup.length > 0 && |
| |
1282
| + // checking first if we're out of time prevents setTimeout(0) |
| |
1283
| + // scheduled in a funcToRun from forcing an extra iteration |
| |
1284
| + currentTime !== endTime && |
| |
1285
| + scheduledLookup[0] <= endTime); |
| |
1286
| + } |
| |
1287
| + } |
| |
1288
| + |
| |
1289
| + return DelayedFunctionScheduler; |
| |
1290
| +}; |
| |
1291
| + |
| |
1292
| +getJasmineRequireObj().ExceptionFormatter = function() { |
| |
1293
| + function ExceptionFormatter() { |
| |
1294
| + this.message = function(error) { |
| |
1295
| + var message = ''; |
| |
1296
| + |
| |
1297
| + if (error.name && error.message) { |
| |
1298
| + message += error.name + ': ' + error.message; |
| |
1299
| + } else { |
| |
1300
| + message += error.toString() + ' thrown'; |
| |
1301
| + } |
| |
1302
| + |
| |
1303
| + if (error.fileName || error.sourceURL) { |
| |
1304
| + message += ' in ' + (error.fileName || error.sourceURL); |
| |
1305
| + } |
| |
1306
| + |
| |
1307
| + if (error.line || error.lineNumber) { |
| |
1308
| + message += ' (line ' + (error.line || error.lineNumber) + ')'; |
| |
1309
| + } |
| |
1310
| + |
| |
1311
| + return message; |
| |
1312
| + }; |
| |
1313
| + |
| |
1314
| + this.stack = function(error) { |
| |
1315
| + return error ? error.stack : null; |
| |
1316
| + }; |
| |
1317
| + } |
| |
1318
| + |
| |
1319
| + return ExceptionFormatter; |
| |
1320
| +}; |
| |
1321
| + |
| |
1322
| +getJasmineRequireObj().Expectation = function() { |
| |
1323
| + |
| |
1324
| + function Expectation(options) { |
| |
1325
| + this.util = options.util || { buildFailureMessage: function() {} }; |
| |
1326
| + this.customEqualityTesters = options.customEqualityTesters || []; |
| |
1327
| + this.actual = options.actual; |
| |
1328
| + this.addExpectationResult = options.addExpectationResult || function(){}; |
| |
1329
| + this.isNot = options.isNot; |
| |
1330
| + |
| |
1331
| + var customMatchers = options.customMatchers || {}; |
| |
1332
| + for (var matcherName in customMatchers) { |
| |
1333
| + this[matcherName] = Expectation.prototype.wrapCompare(matcherName, customMatchers[matcherName]); |
| |
1334
| + } |
| |
1335
| + } |
| |
1336
| + |
| |
1337
| + Expectation.prototype.wrapCompare = function(name, matcherFactory) { |
| |
1338
| + return function() { |
| |
1339
| + var args = Array.prototype.slice.call(arguments, 0), |
| |
1340
| + expected = args.slice(0), |
| |
1341
| + message = ''; |
| |
1342
| + |
| |
1343
| + args.unshift(this.actual); |
| |
1344
| + |
| |
1345
| + var matcher = matcherFactory(this.util, this.customEqualityTesters), |
| |
1346
| + matcherCompare = matcher.compare; |
| |
1347
| + |
| |
1348
| + function defaultNegativeCompare() { |
| |
1349
| + var result = matcher.compare.apply(null, args); |
| |
1350
| + result.pass = !result.pass; |
| |
1351
| + return result; |
| |
1352
| + } |
| |
1353
| + |
| |
1354
| + if (this.isNot) { |
| |
1355
| + matcherCompare = matcher.negativeCompare || defaultNegativeCompare; |
| |
1356
| + } |
| |
1357
| + |
| |
1358
| + var result = matcherCompare.apply(null, args); |
| |
1359
| + |
| |
1360
| + if (!result.pass) { |
| |
1361
| + if (!result.message) { |
| |
1362
| + args.unshift(this.isNot); |
| |
1363
| + args.unshift(name); |
| |
1364
| + message = this.util.buildFailureMessage.apply(null, args); |
| |
1365
| + } else { |
| |
1366
| + if (Object.prototype.toString.apply(result.message) === '[object Function]') { |
| |
1367
| + message = result.message(); |
| |
1368
| + } else { |
| |
1369
| + message = result.message; |
| |
1370
| + } |
| |
1371
| + } |
| |
1372
| + } |
| |
1373
| + |
| |
1374
| + if (expected.length == 1) { |
| |
1375
| + expected = expected[0]; |
| |
1376
| + } |
| |
1377
| + |
| |
1378
| + // TODO: how many of these params are needed? |
| |
1379
| + this.addExpectationResult( |
| |
1380
| + result.pass, |
| |
1381
| + { |
| |
1382
| + matcherName: name, |
| |
1383
| + passed: result.pass, |
| |
1384
| + message: message, |
| |
1385
| + actual: this.actual, |
| |
1386
| + expected: expected // TODO: this may need to be arrayified/sliced |
| |
1387
| + } |
| |
1388
| + ); |
| |
1389
| + }; |
| |
1390
| + }; |
| |
1391
| + |
| |
1392
| + Expectation.addCoreMatchers = function(matchers) { |
| |
1393
| + var prototype = Expectation.prototype; |
| |
1394
| + for (var matcherName in matchers) { |
| |
1395
| + var matcher = matchers[matcherName]; |
| |
1396
| + prototype[matcherName] = prototype.wrapCompare(matcherName, matcher); |
| |
1397
| + } |
| |
1398
| + }; |
| |
1399
| + |
| |
1400
| + Expectation.Factory = function(options) { |
| |
1401
| + options = options || {}; |
| |
1402
| + |
| |
1403
| + var expect = new Expectation(options); |
| |
1404
| + |
| |
1405
| + // TODO: this would be nice as its own Object - NegativeExpectation |
| |
1406
| + // TODO: copy instead of mutate options |
| |
1407
| + options.isNot = true; |
| |
1408
| + expect.not = new Expectation(options); |
| |
1409
| + |
| |
1410
| + return expect; |
| |
1411
| + }; |
| |
1412
| + |
| |
1413
| + return Expectation; |
| |
1414
| +}; |
| |
1415
| + |
| |
1416
| +//TODO: expectation result may make more sense as a presentation of an expectation. |
| |
1417
| +getJasmineRequireObj().buildExpectationResult = function() { |
| |
1418
| + function buildExpectationResult(options) { |
| |
1419
| + var messageFormatter = options.messageFormatter || function() {}, |
| |
1420
| + stackFormatter = options.stackFormatter || function() {}; |
| |
1421
| + |
| |
1422
| + var result = { |
| |
1423
| + matcherName: options.matcherName, |
| |
1424
| + message: message(), |
| |
1425
| + stack: stack(), |
| |
1426
| + passed: options.passed |
| |
1427
| + }; |
| |
1428
| + |
| |
1429
| + if(!result.passed) { |
| |
1430
| + result.expected = options.expected; |
| |
1431
| + result.actual = options.actual; |
| |
1432
| + } |
| |
1433
| + |
| |
1434
| + return result; |
| |
1435
| + |
| |
1436
| + function message() { |
| |
1437
| + if (options.passed) { |
| |
1438
| + return 'Passed.'; |
| |
1439
| + } else if (options.message) { |
| |
1440
| + return options.message; |
| |
1441
| + } else if (options.error) { |
| |
1442
| + return messageFormatter(options.error); |
| |
1443
| + } |
| |
1444
| + return ''; |
| |
1445
| + } |
| |
1446
| + |
| |
1447
| + function stack() { |
| |
1448
| + if (options.passed) { |
| |
1449
| + return ''; |
| |
1450
| + } |
| |
1451
| + |
| |
1452
| + var error = options.error; |
| |
1453
| + if (!error) { |
| |
1454
| + try { |
| |
1455
| + throw new Error(message()); |
| |
1456
| + } catch (e) { |
| |
1457
| + error = e; |
| |
1458
| + } |
| |
1459
| + } |
| |
1460
| + return stackFormatter(error); |
| |
1461
| + } |
| |
1462
| + } |
| |
1463
| + |
| |
1464
| + return buildExpectationResult; |
| |
1465
| +}; |
| |
1466
| + |
| |
1467
| +getJasmineRequireObj().MockDate = function() { |
| |
1468
| + function MockDate(global) { |
| |
1469
| + var self = this; |
| |
1470
| + var currentTime = 0; |
| |
1471
| + |
| |
1472
| + if (!global || !global.Date) { |
| |
1473
| + self.install = function() {}; |
| |
1474
| + self.tick = function() {}; |
| |
1475
| + self.uninstall = function() {}; |
| |
1476
| + return self; |
| |
1477
| + } |
| |
1478
| + |
| |
1479
| + var GlobalDate = global.Date; |
| |
1480
| + |
| |
1481
| + self.install = function(mockDate) { |
| |
1482
| + if (mockDate instanceof GlobalDate) { |
| |
1483
| + currentTime = mockDate.getTime(); |
| |
1484
| + } else { |
| |
1485
| + currentTime = new GlobalDate().getTime(); |
| |
1486
| + } |
| |
1487
| + |
| |
1488
| + global.Date = FakeDate; |
| |
1489
| + }; |
| |
1490
| + |
| |
1491
| + self.tick = function(millis) { |
| |
1492
| + millis = millis || 0; |
| |
1493
| + currentTime = currentTime + millis; |
| |
1494
| + }; |
| |
1495
| + |
| |
1496
| + self.uninstall = function() { |
| |
1497
| + currentTime = 0; |
| |
1498
| + global.Date = GlobalDate; |
| |
1499
| + }; |
| |
1500
| + |
| |
1501
| + createDateProperties(); |
| |
1502
| + |
| |
1503
| + return self; |
| |
1504
| + |
| |
1505
| + function FakeDate() { |
| |
1506
| + switch(arguments.length) { |
| |
1507
| + case 0: |
| |
1508
| + return new GlobalDate(currentTime); |
| |
1509
| + case 1: |
| |
1510
| + return new GlobalDate(arguments[0]); |
| |
1511
| + case 2: |
| |
1512
| + return new GlobalDate(arguments[0], arguments[1]); |
| |
1513
| + case 3: |
| |
1514
| + return new GlobalDate(arguments[0], arguments[1], arguments[2]); |
| |
1515
| + case 4: |
| |
1516
| + return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]); |
| |
1517
| + case 5: |
| |
1518
| + return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], |
| |
1519
| + arguments[4]); |
| |
1520
| + case 6: |
| |
1521
| + return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], |
| |
1522
| + arguments[4], arguments[5]); |
| |
1523
| + default: |
| |
1524
| + return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3], |
| |
1525
| + arguments[4], arguments[5], arguments[6]); |
| |
1526
| + } |
| |
1527
| + } |
| |
1528
| + |
| |
1529
| + function createDateProperties() { |
| |
1530
| + FakeDate.prototype = GlobalDate.prototype; |
| |
1531
| + |
| |
1532
| + FakeDate.now = function() { |
| |
1533
| + if (GlobalDate.now) { |
| |
1534
| + return currentTime; |
| |
1535
| + } else { |
| |
1536
| + throw new Error('Browser does not support Date.now()'); |
| |
1537
| + } |
| |
1538
| + }; |
| |
1539
| + |
| |
1540
| + FakeDate.toSource = GlobalDate.toSource; |
| |
1541
| + FakeDate.toString = GlobalDate.toString; |
| |
1542
| + FakeDate.parse = GlobalDate.parse; |
| |
1543
| + FakeDate.UTC = GlobalDate.UTC; |
| |
1544
| + } |
| |
1545
| + } |
| |
1546
| + |
| |
1547
| + return MockDate; |
| |
1548
| +}; |
| |
1549
| + |
| |
1550
| +getJasmineRequireObj().pp = function(j$) { |
| |
1551
| + |
| |
1552
| + function PrettyPrinter() { |
| |
1553
| + this.ppNestLevel_ = 0; |
| |
1554
| + this.seen = []; |
| |
1555
| + } |
| |
1556
| + |
| |
1557
| + PrettyPrinter.prototype.format = function(value) { |
| |
1558
| + this.ppNestLevel_++; |
| |
1559
| + try { |
| |
1560
| + if (j$.util.isUndefined(value)) { |
| |
1561
| + this.emitScalar('undefined'); |
| |
1562
| + } else if (value === null) { |
| |
1563
| + this.emitScalar('null'); |
| |
1564
| + } else if (value === 0 && 1/value === -Infinity) { |
| |
1565
| + this.emitScalar('-0'); |
| |
1566
| + } else if (value === j$.getGlobal()) { |
| |
1567
| + this.emitScalar('<global>'); |
| |
1568
| + } else if (value.jasmineToString) { |
| |
1569
| + this.emitScalar(value.jasmineToString()); |
| |
1570
| + } else if (typeof value === 'string') { |
| |
1571
| + this.emitString(value); |
| |
1572
| + } else if (j$.isSpy(value)) { |
| |
1573
| + this.emitScalar('spy on ' + value.and.identity()); |
| |
1574
| + } else if (value instanceof RegExp) { |
| |
1575
| + this.emitScalar(value.toString()); |
| |
1576
| + } else if (typeof value === 'function') { |
| |
1577
| + this.emitScalar('Function'); |
| |
1578
| + } else if (typeof value.nodeType === 'number') { |
| |
1579
| + this.emitScalar('HTMLNode'); |
| |
1580
| + } else if (value instanceof Date) { |
| |
1581
| + this.emitScalar('Date(' + value + ')'); |
| |
1582
| + } else if (j$.util.arrayContains(this.seen, value)) { |
| |
1583
| + this.emitScalar('<circular reference: ' + (j$.isArray_(value) ? 'Array' : 'Object') + '>'); |
| |
1584
| + } else if (j$.isArray_(value) || j$.isA_('Object', value)) { |
| |
1585
| + this.seen.push(value); |
| |
1586
| + if (j$.isArray_(value)) { |
| |
1587
| + this.emitArray(value); |
| |
1588
| + } else { |
| |
1589
| + this.emitObject(value); |
| |
1590
| + } |
| |
1591
| + this.seen.pop(); |
| |
1592
| + } else { |
| |
1593
| + this.emitScalar(value.toString()); |
| |
1594
| + } |
| |
1595
| + } finally { |
| |
1596
| + this.ppNestLevel_--; |
| |
1597
| + } |
| |
1598
| + }; |
| |
1599
| + |
| |
1600
| + PrettyPrinter.prototype.iterateObject = function(obj, fn) { |
| |
1601
| + for (var property in obj) { |
| |
1602
| + if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; } |
| |
1603
| + fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) && |
| |
1604
| + obj.__lookupGetter__(property) !== null) : false); |
| |
1605
| + } |
| |
1606
| + }; |
| |
1607
| + |
| |
1608
| + PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_; |
| |
1609
| + PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_; |
| |
1610
| + PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_; |
| |
1611
| + PrettyPrinter.prototype.emitString = j$.unimplementedMethod_; |
| |
1612
| + |
| |
1613
| + function StringPrettyPrinter() { |
| |
1614
| + PrettyPrinter.call(this); |
| |
1615
| + |
| |
1616
| + this.string = ''; |
| |
1617
| + } |
| |
1618
| + |
| |
1619
| + j$.util.inherit(StringPrettyPrinter, PrettyPrinter); |
| |
1620
| + |
| |
1621
| + StringPrettyPrinter.prototype.emitScalar = function(value) { |
| |
1622
| + this.append(value); |
| |
1623
| + }; |
| |
1624
| + |
| |
1625
| + StringPrettyPrinter.prototype.emitString = function(value) { |
| |
1626
| + this.append('\'' + value + '\''); |
| |
1627
| + }; |
| |
1628
| + |
| |
1629
| + StringPrettyPrinter.prototype.emitArray = function(array) { |
| |
1630
| + if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { |
| |
1631
| + this.append('Array'); |
| |
1632
| + return; |
| |
1633
| + } |
| |
1634
| + var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH); |
| |
1635
| + this.append('[ '); |
| |
1636
| + for (var i = 0; i < length; i++) { |
| |
1637
| + if (i > 0) { |
| |
1638
| + this.append(', '); |
| |
1639
| + } |
| |
1640
| + this.format(array[i]); |
| |
1641
| + } |
| |
1642
| + if(array.length > length){ |
| |
1643
| + this.append(', ...'); |
| |
1644
| + } |
| |
1645
| + this.append(' ]'); |
| |
1646
| + }; |
| |
1647
| + |
| |
1648
| + StringPrettyPrinter.prototype.emitObject = function(obj) { |
| |
1649
| + var constructorName = obj.constructor ? j$.fnNameFor(obj.constructor) : 'null'; |
| |
1650
| + this.append(constructorName); |
| |
1651
| + |
| |
1652
| + if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) { |
| |
1653
| + return; |
| |
1654
| + } |
| |
1655
| + |
| |
1656
| + var self = this; |
| |
1657
| + this.append('({ '); |
| |
1658
| + var first = true; |
| |
1659
| + |
| |
1660
| + this.iterateObject(obj, function(property, isGetter) { |
| |
1661
| + if (first) { |
| |
1662
| + first = false; |
| |
1663
| + } else { |
| |
1664
| + self.append(', '); |
| |
1665
| + } |
| |
1666
| + |
| |
1667
| + self.append(property); |
| |
1668
| + self.append(': '); |
| |
1669
| + if (isGetter) { |
| |
1670
| + self.append('<getter>'); |
| |
1671
| + } else { |
| |
1672
| + self.format(obj[property]); |
| |
1673
| + } |
| |
1674
| + }); |
| |
1675
| + |
| |
1676
| + this.append(' })'); |
| |
1677
| + }; |
| |
1678
| + |
| |
1679
| + StringPrettyPrinter.prototype.append = function(value) { |
| |
1680
| + this.string += value; |
| |
1681
| + }; |
| |
1682
| + |
| |
1683
| + return function(value) { |
| |
1684
| + var stringPrettyPrinter = new StringPrettyPrinter(); |
| |
1685
| + stringPrettyPrinter.format(value); |
| |
1686
| + return stringPrettyPrinter.string; |
| |
1687
| + }; |
| |
1688
| +}; |
| |
1689
| + |
| |
1690
| +getJasmineRequireObj().QueueRunner = function(j$) { |
| |
1691
| + |
| |
1692
| + function once(fn) { |
| |
1693
| + var called = false; |
| |
1694
| + return function() { |
| |
1695
| + if (!called) { |
| |
1696
| + called = true; |
| |
1697
| + fn(); |
| |
1698
| + } |
| |
1699
| + }; |
| |
1700
| + } |
| |
1701
| + |
| |
1702
| + function QueueRunner(attrs) { |
| |
1703
| + this.queueableFns = attrs.queueableFns || []; |
| |
1704
| + this.onComplete = attrs.onComplete || function() {}; |
| |
1705
| + this.clearStack = attrs.clearStack || function(fn) {fn();}; |
| |
1706
| + this.onException = attrs.onException || function() {}; |
| |
1707
| + this.catchException = attrs.catchException || function() { return true; }; |
| |
1708
| + this.userContext = attrs.userContext || {}; |
| |
1709
| + this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout}; |
| |
1710
| + this.fail = attrs.fail || function() {}; |
| |
1711
| + } |
| |
1712
| + |
| |
1713
| + QueueRunner.prototype.execute = function() { |
| |
1714
| + this.run(this.queueableFns, 0); |
| |
1715
| + }; |
| |
1716
| + |
| |
1717
| + QueueRunner.prototype.run = function(queueableFns, recursiveIndex) { |
| |
1718
| + var length = queueableFns.length, |
| |
1719
| + self = this, |
| |
1720
| + iterativeIndex; |
| |
1721
| + |
| |
1722
| + |
| |
1723
| + for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) { |
| |
1724
| + var queueableFn = queueableFns[iterativeIndex]; |
| |
1725
| + if (queueableFn.fn.length > 0) { |
| |
1726
| + attemptAsync(queueableFn); |
| |
1727
| + return; |
| |
1728
| + } else { |
| |
1729
| + attemptSync(queueableFn); |
| |
1730
| + } |
| |
1731
| + } |
| |
1732
| + |
| |
1733
| + var runnerDone = iterativeIndex >= length; |
| |
1734
| + |
| |
1735
| + if (runnerDone) { |
| |
1736
| + this.clearStack(this.onComplete); |
| |
1737
| + } |
| |
1738
| + |
| |
1739
| + function attemptSync(queueableFn) { |
| |
1740
| + try { |
| |
1741
| + queueableFn.fn.call(self.userContext); |
| |
1742
| + } catch (e) { |
| |
1743
| + handleException(e, queueableFn); |
| |
1744
| + } |
| |
1745
| + } |
| |
1746
| + |
| |
1747
| + function attemptAsync(queueableFn) { |
| |
1748
| + var clearTimeout = function () { |
| |
1749
| + Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]); |
| |
1750
| + }, |
| |
1751
| + next = once(function () { |
| |
1752
| + clearTimeout(timeoutId); |
| |
1753
| + self.run(queueableFns, iterativeIndex + 1); |
| |
1754
| + }), |
| |
1755
| + timeoutId; |
| |
1756
| + |
| |
1757
| + next.fail = function() { |
| |
1758
| + self.fail.apply(null, arguments); |
| |
1759
| + next(); |
| |
1760
| + }; |
| |
1761
| + |
| |
1762
| + if (queueableFn.timeout) { |
| |
1763
| + timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() { |
| |
1764
| + var error = new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'); |
| |
1765
| + onException(error, queueableFn); |
| |
1766
| + next(); |
| |
1767
| + }, queueableFn.timeout()]]); |
| |
1768
| + } |
| |
1769
| + |
| |
1770
| + try { |
| |
1771
| + queueableFn.fn.call(self.userContext, next); |
| |
1772
| + } catch (e) { |
| |
1773
| + handleException(e, queueableFn); |
| |
1774
| + next(); |
| |
1775
| + } |
| |
1776
| + } |
| |
1777
| + |
| |
1778
| + function onException(e, queueableFn) { |
| |
1779
| + self.onException(e); |
| |
1780
| + } |
| |
1781
| + |
| |
1782
| + function handleException(e, queueableFn) { |
| |
1783
| + onException(e, queueableFn); |
| |
1784
| + if (!self.catchException(e)) { |
| |
1785
| + //TODO: set a var when we catch an exception and |
| |
1786
| + //use a finally block to close the loop in a nice way.. |
| |
1787
| + throw e; |
| |
1788
| + } |
| |
1789
| + } |
| |
1790
| + }; |
| |
1791
| + |
| |
1792
| + return QueueRunner; |
| |
1793
| +}; |
| |
1794
| + |
| |
1795
| +getJasmineRequireObj().ReportDispatcher = function() { |
| |
1796
| + function ReportDispatcher(methods) { |
| |
1797
| + |
| |
1798
| + var dispatchedMethods = methods || []; |
| |
1799
| + |
| |
1800
| + for (var i = 0; i < dispatchedMethods.length; i++) { |
| |
1801
| + var method = dispatchedMethods[i]; |
| |
1802
| + this[method] = (function(m) { |
| |
1803
| + return function() { |
| |
1804
| + dispatch(m, arguments); |
| |
1805
| + }; |
| |
1806
| + }(method)); |
| |
1807
| + } |
| |
1808
| + |
| |
1809
| + var reporters = []; |
| |
1810
| + |
| |
1811
| + this.addReporter = function(reporter) { |
| |
1812
| + reporters.push(reporter); |
| |
1813
| + }; |
| |
1814
| + |
| |
1815
| + return this; |
| |
1816
| + |
| |
1817
| + function dispatch(method, args) { |
| |
1818
| + for (var i = 0; i < reporters.length; i++) { |
| |
1819
| + var reporter = reporters[i]; |
| |
1820
| + if (reporter[method]) { |
| |
1821
| + reporter[method].apply(reporter, args); |
| |
1822
| + } |
| |
1823
| + } |
| |
1824
| + } |
| |
1825
| + } |
| |
1826
| + |
| |
1827
| + return ReportDispatcher; |
| |
1828
| +}; |
| |
1829
| + |
| |
1830
| + |
| |
1831
| +getJasmineRequireObj().SpyRegistry = function(j$) { |
| |
1832
| + |
| |
1833
| + function SpyRegistry(options) { |
| |
1834
| + options = options || {}; |
| |
1835
| + var currentSpies = options.currentSpies || function() { return []; }; |
| |
1836
| + |
| |
1837
| + this.spyOn = function(obj, methodName) { |
| |
1838
| + if (j$.util.isUndefined(obj)) { |
| |
1839
| + throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()'); |
| |
1840
| + } |
| |
1841
| + |
| |
1842
| + if (j$.util.isUndefined(methodName)) { |
| |
1843
| + throw new Error('No method name supplied'); |
| |
1844
| + } |
| |
1845
| + |
| |
1846
| + if (j$.util.isUndefined(obj[methodName])) { |
| |
1847
| + throw new Error(methodName + '() method does not exist'); |
| |
1848
| + } |
| |
1849
| + |
| |
1850
| + if (obj[methodName] && j$.isSpy(obj[methodName])) { |
| |
1851
| + //TODO?: should this return the current spy? Downside: may cause user confusion about spy state |
| |
1852
| + throw new Error(methodName + ' has already been spied upon'); |
| |
1853
| + } |
| |
1854
| + |
| |
1855
| + var spy = j$.createSpy(methodName, obj[methodName]); |
| |
1856
| + |
| |
1857
| + currentSpies().push({ |
| |
1858
| + spy: spy, |
| |
1859
| + baseObj: obj, |
| |
1860
| + methodName: methodName, |
| |
1861
| + originalValue: obj[methodName] |
| |
1862
| + }); |
| |
1863
| + |
| |
1864
| + obj[methodName] = spy; |
| |
1865
| + |
| |
1866
| + return spy; |
| |
1867
| + }; |
| |
1868
| + |
| |
1869
| + this.clearSpies = function() { |
| |
1870
| + var spies = currentSpies(); |
| |
1871
| + for (var i = 0; i < spies.length; i++) { |
| |
1872
| + var spyEntry = spies[i]; |
| |
1873
| + spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue; |
| |
1874
| + } |
| |
1875
| + }; |
| |
1876
| + } |
| |
1877
| + |
| |
1878
| + return SpyRegistry; |
| |
1879
| +}; |
| |
1880
| + |
| |
1881
| +getJasmineRequireObj().SpyStrategy = function() { |
| |
1882
| + |
| |
1883
| + function SpyStrategy(options) { |
| |
1884
| + options = options || {}; |
| |
1885
| + |
| |
1886
| + var identity = options.name || 'unknown', |
| |
1887
| + originalFn = options.fn || function() {}, |
| |
1888
| + getSpy = options.getSpy || function() {}, |
| |
1889
| + plan = function() {}; |
| |
1890
| + |
| |
1891
| + this.identity = function() { |
| |
1892
| + return identity; |
| |
1893
| + }; |
| |
1894
| + |
| |
1895
| + this.exec = function() { |
| |
1896
| + return plan.apply(this, arguments); |
| |
1897
| + }; |
| |
1898
| + |
| |
1899
| + this.callThrough = function() { |
| |
1900
| + plan = originalFn; |
| |
1901
| + return getSpy(); |
| |
1902
| + }; |
| |
1903
| + |
| |
1904
| + this.returnValue = function(value) { |
| |
1905
| + plan = function() { |
| |
1906
| + return value; |
| |
1907
| + }; |
| |
1908
| + return getSpy(); |
| |
1909
| + }; |
| |
1910
| + |
| |
1911
| + this.returnValues = function() { |
| |
1912
| + var values = Array.prototype.slice.call(arguments); |
| |
1913
| + plan = function () { |
| |
1914
| + return values.shift(); |
| |
1915
| + }; |
| |
1916
| + return getSpy(); |
| |
1917
| + }; |
| |
1918
| + |
| |
1919
| + this.throwError = function(something) { |
| |
1920
| + var error = (something instanceof Error) ? something : new Error(something); |
| |
1921
| + plan = function() { |
| |
1922
| + throw error; |
| |
1923
| + }; |
| |
1924
| + return getSpy(); |
| |
1925
| + }; |
| |
1926
| + |
| |
1927
| + this.callFake = function(fn) { |
| |
1928
| + plan = fn; |
| |
1929
| + return getSpy(); |
| |
1930
| + }; |
| |
1931
| + |
| |
1932
| + this.stub = function(fn) { |
| |
1933
| + plan = function() {}; |
| |
1934
| + return getSpy(); |
| |
1935
| + }; |
| |
1936
| + } |
| |
1937
| + |
| |
1938
| + return SpyStrategy; |
| |
1939
| +}; |
| |
1940
| + |
| |
1941
| +getJasmineRequireObj().Suite = function() { |
| |
1942
| + function Suite(attrs) { |
| |
1943
| + this.env = attrs.env; |
| |
1944
| + this.id = attrs.id; |
| |
1945
| + this.parentSuite = attrs.parentSuite; |
| |
1946
| + this.description = attrs.description; |
| |
1947
| + this.onStart = attrs.onStart || function() {}; |
| |
1948
| + this.resultCallback = attrs.resultCallback || function() {}; |
| |
1949
| + this.clearStack = attrs.clearStack || function(fn) {fn();}; |
| |
1950
| + this.expectationFactory = attrs.expectationFactory; |
| |
1951
| + this.expectationResultFactory = attrs.expectationResultFactory; |
| |
1952
| + this.runnablesExplictlySetGetter = attrs.runnablesExplictlySetGetter || function() {}; |
| |
1953
| + |
| |
1954
| + this.beforeFns = []; |
| |
1955
| + this.afterFns = []; |
| |
1956
| + this.beforeAllFns = []; |
| |
1957
| + this.afterAllFns = []; |
| |
1958
| + this.queueRunner = attrs.queueRunner || function() {}; |
| |
1959
| + this.disabled = false; |
| |
1960
| + |
| |
1961
| + this.children = []; |
| |
1962
| + |
| |
1963
| + this.result = { |
| |
1964
| + id: this.id, |
| |
1965
| + description: this.description, |
| |
1966
| + fullName: this.getFullName(), |
| |
1967
| + failedExpectations: [] |
| |
1968
| + }; |
| |
1969
| + } |
| |
1970
| + |
| |
1971
| + Suite.prototype.expect = function(actual) { |
| |
1972
| + return this.expectationFactory(actual, this); |
| |
1973
| + }; |
| |
1974
| + |
| |
1975
| + Suite.prototype.getFullName = function() { |
| |
1976
| + var fullName = this.description; |
| |
1977
| + for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) { |
| |
1978
| + if (parentSuite.parentSuite) { |
| |
1979
| + fullName = parentSuite.description + ' ' + fullName; |
| |
1980
| + } |
| |
1981
| + } |
| |
1982
| + return fullName; |
| |
1983
| + }; |
| |
1984
| + |
| |
1985
| + Suite.prototype.disable = function() { |
| |
1986
| + this.disabled = true; |
| |
1987
| + }; |
| |
1988
| + |
| |
1989
| + Suite.prototype.beforeEach = function(fn) { |
| |
1990
| + this.beforeFns.unshift(fn); |
| |
1991
| + }; |
| |
1992
| + |
| |
1993
| + Suite.prototype.beforeAll = function(fn) { |
| |
1994
| + this.beforeAllFns.push(fn); |
| |
1995
| + }; |
| |
1996
| + |
| |
1997
| + Suite.prototype.afterEach = function(fn) { |
| |
1998
| + this.afterFns.unshift(fn); |
| |
1999
| + }; |
| |
2000
| + |
| |
2001
| + Suite.prototype.afterAll = function(fn) { |
| |
2002
| + this.afterAllFns.push(fn); |
| |
2003
| + }; |
| |
2004
| + |
| |
2005
| + Suite.prototype.addChild = function(child) { |
| |
2006
| + this.children.push(child); |
| |
2007
| + }; |
| |
2008
| + |
| |
2009
| + Suite.prototype.status = function() { |
| |
2010
| + if (this.disabled) { |
| |
2011
| + return 'disabled'; |
| |
2012
| + } |
| |
2013
| + |
| |
2014
| + if (this.result.failedExpectations.length > 0) { |
| |
2015
| + return 'failed'; |
| |
2016
| + } else { |
| |
2017
| + return 'finished'; |
| |
2018
| + } |
| |
2019
| + }; |
| |
2020
| + |
| |
2021
| + Suite.prototype.execute = function(onComplete) { |
| |
2022
| + var self = this; |
| |
2023
| + |
| |
2024
| + this.onStart(this); |
| |
2025
| + |
| |
2026
| + if (this.disabled) { |
| |
2027
| + complete(); |
| |
2028
| + return; |
| |
2029
| + } |
| |
2030
| + |
| |
2031
| + var allFns = []; |
| |
2032
| + |
| |
2033
| + for (var i = 0; i < this.children.length; i++) { |
| |
2034
| + allFns.push(wrapChildAsAsync(this.children[i])); |
| |
2035
| + } |
| |
2036
| + |
| |
2037
| + if (this.isExecutable()) { |
| |
2038
| + allFns = this.beforeAllFns.concat(allFns); |
| |
2039
| + allFns = allFns.concat(this.afterAllFns); |
| |
2040
| + } |
| |
2041
| + |
| |
2042
| + this.queueRunner({ |
| |
2043
| + queueableFns: allFns, |
| |
2044
| + onComplete: complete, |
| |
2045
| + userContext: this.sharedUserContext(), |
| |
2046
| + onException: function() { self.onException.apply(self, arguments); } |
| |
2047
| + }); |
| |
2048
| + |
| |
2049
| + function complete() { |
| |
2050
| + self.result.status = self.status(); |
| |
2051
| + self.resultCallback(self.result); |
| |
2052
| + |
| |
2053
| + if (onComplete) { |
| |
2054
| + onComplete(); |
| |
2055
| + } |
| |
2056
| + } |
| |
2057
| + |
| |
2058
| + function wrapChildAsAsync(child) { |
| |
2059
| + return { fn: function(done) { child.execute(done); } }; |
| |
2060
| + } |
| |
2061
| + }; |
| |
2062
| + |
| |
2063
| + Suite.prototype.isExecutable = function() { |
| |
2064
| + var runnablesExplicitlySet = this.runnablesExplictlySetGetter(); |
| |
2065
| + return !runnablesExplicitlySet && hasExecutableChild(this.children); |
| |
2066
| + }; |
| |
2067
| + |
| |
2068
| + Suite.prototype.sharedUserContext = function() { |
| |
2069
| + if (!this.sharedContext) { |
| |
2070
| + this.sharedContext = this.parentSuite ? clone(this.parentSuite.sharedUserContext()) : {}; |
| |
2071
| + } |
| |
2072
| + |
| |
2073
| + return this.sharedContext; |
| |
2074
| + }; |
| |
2075
| + |
| |
2076
| + Suite.prototype.clonedSharedUserContext = function() { |
| |
2077
| + return clone(this.sharedUserContext()); |
| |
2078
| + }; |
| |
2079
| + |
| |
2080
| + Suite.prototype.onException = function() { |
| |
2081
| + if(isAfterAll(this.children)) { |
| |
2082
| + var data = { |
| |
2083
| + matcherName: '', |
| |
2084
| + passed: false, |
| |
2085
| + expected: '', |
| |
2086
| + actual: '', |
| |
2087
| + error: arguments[0] |
| |
2088
| + }; |
| |
2089
| + this.result.failedExpectations.push(this.expectationResultFactory(data)); |
| |
2090
| + } else { |
| |
2091
| + for (var i = 0; i < this.children.length; i++) { |
| |
2092
| + var child = this.children[i]; |
| |
2093
| + child.onException.apply(child, arguments); |
| |
2094
| + } |
| |
2095
| + } |
| |
2096
| + }; |
| |
2097
| + |
| |
2098
| + Suite.prototype.addExpectationResult = function () { |
| |
2099
| + if(isAfterAll(this.children) && isFailure(arguments)){ |
| |
2100
| + var data = arguments[1]; |
| |
2101
| + this.result.failedExpectations.push(this.expectationResultFactory(data)); |
| |
2102
| + } else { |
| |
2103
| + for (var i = 0; i < this.children.length; i++) { |
| |
2104
| + var child = this.children[i]; |
| |
2105
| + child.addExpectationResult.apply(child, arguments); |
| |
2106
| + } |
| |
2107
| + } |
| |
2108
| + }; |
| |
2109
| + |
| |
2110
| + function isAfterAll(children) { |
| |
2111
| + return children && children[0].result.status; |
| |
2112
| + } |
| |
2113
| + |
| |
2114
| + function isFailure(args) { |
| |
2115
| + return !args[0]; |
| |
2116
| + } |
| |
2117
| + |
| |
2118
| + function hasExecutableChild(children) { |
| |
2119
| + var foundActive = false; |
| |
2120
| + for (var i = 0; i < children.length; i++) { |
| |
2121
| + if (children[i].isExecutable()) { |
| |
2122
| + foundActive = true; |
| |
2123
| + break; |
| |
2124
| + } |
| |
2125
| + } |
| |
2126
| + return foundActive; |
| |
2127
| + } |
| |
2128
| + |
| |
2129
| + function clone(obj) { |
| |
2130
| + var clonedObj = {}; |
| |
2131
| + for (var prop in obj) { |
| |
2132
| + if (obj.hasOwnProperty(prop)) { |
| |
2133
| + clonedObj[prop] = obj[prop]; |
| |
2134
| + } |
| |
2135
| + } |
| |
2136
| + |
| |
2137
| + return clonedObj; |
| |
2138
| + } |
| |
2139
| + |
| |
2140
| + return Suite; |
| |
2141
| +}; |
| |
2142
| + |
| |
2143
| +if (typeof window == void 0 && typeof exports == 'object') { |
| |
2144
| + exports.Suite = jasmineRequire.Suite; |
| |
2145
| +} |
| |
2146
| + |
| |
2147
| +getJasmineRequireObj().Timer = function() { |
| |
2148
| + var defaultNow = (function(Date) { |
| |
2149
| + return function() { return new Date().getTime(); }; |
| |
2150
| + })(Date); |
| |
2151
| + |
| |
2152
| + function Timer(options) { |
| |
2153
| + options = options || {}; |
| |
2154
| + |
| |
2155
| + var now = options.now || defaultNow, |
| |
2156
| + startTime; |
| |
2157
| + |
| |
2158
| + this.start = function() { |
| |
2159
| + startTime = now(); |
| |
2160
| + }; |
| |
2161
| + |
| |
2162
| + this.elapsed = function() { |
| |
2163
| + return now() - startTime; |
| |
2164
| + }; |
| |
2165
| + } |
| |
2166
| + |
| |
2167
| + return Timer; |
| |
2168
| +}; |
| |
2169
| + |
| |
2170
| +getJasmineRequireObj().Any = function() { |
| |
2171
| + |
| |
2172
| + function Any(expectedObject) { |
| |
2173
| + this.expectedObject = expectedObject; |
| |
2174
| + } |
| |
2175
| + |
| |
2176
| + Any.prototype.asymmetricMatch = function(other) { |
| |
2177
| + if (this.expectedObject == String) { |
| |
2178
| + return typeof other == 'string' || other instanceof String; |
| |
2179
| + } |
| |
2180
| + |
| |
2181
| + if (this.expectedObject == Number) { |
| |
2182
| + return typeof other == 'number' || other instanceof Number; |
| |
2183
| + } |
| |
2184
| + |
| |
2185
| + if (this.expectedObject == Function) { |
| |
2186
| + return typeof other == 'function' || other instanceof Function; |
| |
2187
| + } |
| |
2188
| + |
| |
2189
| + if (this.expectedObject == Object) { |
| |
2190
| + return typeof other == 'object'; |
| |
2191
| + } |
| |
2192
| + |
| |
2193
| + if (this.expectedObject == Boolean) { |
| |
2194
| + return typeof other == 'boolean'; |
| |
2195
| + } |
| |
2196
| + |
| |
2197
| + return other instanceof this.expectedObject; |
| |
2198
| + }; |
| |
2199
| + |
| |
2200
| + Any.prototype.jasmineToString = function() { |
| |
2201
| + return '<jasmine.any(' + this.expectedObject + ')>'; |
| |
2202
| + }; |
| |
2203
| + |
| |
2204
| + return Any; |
| |
2205
| +}; |
| |
2206
| + |
| |
2207
| +getJasmineRequireObj().Anything = function(j$) { |
| |
2208
| + |
| |
2209
| + function Anything() {} |
| |
2210
| + |
| |
2211
| + Anything.prototype.asymmetricMatch = function(other) { |
| |
2212
| + return !j$.util.isUndefined(other) && other !== null; |
| |
2213
| + }; |
| |
2214
| + |
| |
2215
| + Anything.prototype.jasmineToString = function() { |
| |
2216
| + return '<jasmine.anything>'; |
| |
2217
| + }; |
| |
2218
| + |
| |
2219
| + return Anything; |
| |
2220
| +}; |
| |
2221
| + |
| |
2222
| +getJasmineRequireObj().ArrayContaining = function(j$) { |
| |
2223
| + function ArrayContaining(sample) { |
| |
2224
| + this.sample = sample; |
| |
2225
| + } |
| |
2226
| + |
| |
2227
| + ArrayContaining.prototype.asymmetricMatch = function(other) { |
| |
2228
| + var className = Object.prototype.toString.call(this.sample); |
| |
2229
| + if (className !== '[object Array]') { throw new Error('You must provide an array to arrayContaining, not \'' + this.sample + '\'.'); } |
| |
2230
| + |
| |
2231
| + for (var i = 0; i < this.sample.length; i++) { |
| |
2232
| + var item = this.sample[i]; |
| |
2233
| + if (!j$.matchersUtil.contains(other, item)) { |
| |
2234
| + return false; |
| |
2235
| + } |
| |
2236
| + } |
| |
2237
| + |
| |
2238
| + return true; |
| |
2239
| + }; |
| |
2240
| + |
| |
2241
| + ArrayContaining.prototype.jasmineToString = function () { |
| |
2242
| + return '<jasmine.arrayContaining(' + jasmine.pp(this.sample) +')>'; |
| |
2243
| + }; |
| |
2244
| + |
| |
2245
| + return ArrayContaining; |
| |
2246
| +}; |
| |
2247
| + |
| |
2248
| +getJasmineRequireObj().ObjectContaining = function(j$) { |
| |
2249
| + |
| |
2250
| + function ObjectContaining(sample) { |
| |
2251
| + this.sample = sample; |
| |
2252
| + } |
| |
2253
| + |
| |
2254
| + ObjectContaining.prototype.asymmetricMatch = function(other) { |
| |
2255
| + if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); } |
| |
2256
| + |
| |
2257
| + for (var property in this.sample) { |
| |
2258
| + if (!Object.prototype.hasOwnProperty.call(other, property) || |
| |
2259
| + !j$.matchersUtil.equals(this.sample[property], other[property])) { |
| |
2260
| + return false; |
| |
2261
| + } |
| |
2262
| + } |
| |
2263
| + |
| |
2264
| + return true; |
| |
2265
| + }; |
| |
2266
| + |
| |
2267
| + ObjectContaining.prototype.jasmineToString = function() { |
| |
2268
| + return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>'; |
| |
2269
| + }; |
| |
2270
| + |
| |
2271
| + return ObjectContaining; |
| |
2272
| +}; |
| |
2273
| + |
| |
2274
| +getJasmineRequireObj().StringMatching = function(j$) { |
| |
2275
| + |
| |
2276
| + function StringMatching(expected) { |
| |
2277
| + if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) { |
| |
2278
| + throw new Error('Expected is not a String or a RegExp'); |
| |
2279
| + } |
| |
2280
| + |
| |
2281
| + this.regexp = new RegExp(expected); |
| |
2282
| + } |
| |
2283
| + |
| |
2284
| + StringMatching.prototype.asymmetricMatch = function(other) { |
| |
2285
| + return this.regexp.test(other); |
| |
2286
| + }; |
| |
2287
| + |
| |
2288
| + StringMatching.prototype.jasmineToString = function() { |
| |
2289
| + return '<jasmine.stringMatching(' + this.regexp + ')>'; |
| |
2290
| + }; |
| |
2291
| + |
| |
2292
| + return StringMatching; |
| |
2293
| +}; |
| |
2294
| + |
| |
2295
| +getJasmineRequireObj().matchersUtil = function(j$) { |
| |
2296
| + // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter? |
| |
2297
| + |
| |
2298
| + return { |
| |
2299
| + equals: function(a, b, customTesters) { |
| |
2300
| + customTesters = customTesters || []; |
| |
2301
| + |
| |
2302
| + return eq(a, b, [], [], customTesters); |
| |
2303
| + }, |
| |
2304
| + |
| |
2305
| + contains: function(haystack, needle, customTesters) { |
| |
2306
| + customTesters = customTesters || []; |
| |
2307
| + |
| |
2308
| + if ((Object.prototype.toString.apply(haystack) === '[object Array]') || |
| |
2309
| + (!!haystack && !haystack.indexOf)) |
| |
2310
| + { |
| |
2311
| + for (var i = 0; i < haystack.length; i++) { |
| |
2312
| + if (eq(haystack[i], needle, [], [], customTesters)) { |
| |
2313
| + return true; |
| |
2314
| + } |
| |
2315
| + } |
| |
2316
| + return false; |
| |
2317
| + } |
| |
2318
| + |
| |
2319
| + return !!haystack && haystack.indexOf(needle) >= 0; |
| |
2320
| + }, |
| |
2321
| + |
| |
2322
| + buildFailureMessage: function() { |
| |
2323
| + var args = Array.prototype.slice.call(arguments, 0), |
| |
2324
| + matcherName = args[0], |
| |
2325
| + isNot = args[1], |
| |
2326
| + actual = args[2], |
| |
2327
| + expected = args.slice(3), |
| |
2328
| + englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); }); |
| |
2329
| + |
| |
2330
| + var message = 'Expected ' + |
| |
2331
| + j$.pp(actual) + |
| |
2332
| + (isNot ? ' not ' : ' ') + |
| |
2333
| + englishyPredicate; |
| |
2334
| + |
| |
2335
| + if (expected.length > 0) { |
| |
2336
| + for (var i = 0; i < expected.length; i++) { |
| |
2337
| + if (i > 0) { |
| |
2338
| + message += ','; |
| |
2339
| + } |
| |
2340
| + message += ' ' + j$.pp(expected[i]); |
| |
2341
| + } |
| |
2342
| + } |
| |
2343
| + |
| |
2344
| + return message + '.'; |
| |
2345
| + } |
| |
2346
| + }; |
| |
2347
| + |
| |
2348
| + function isAsymmetric(obj) { |
| |
2349
| + return obj && j$.isA_('Function', obj.asymmetricMatch); |
| |
2350
| + } |
| |
2351
| + |
| |
2352
| + function asymmetricMatch(a, b) { |
| |
2353
| + var asymmetricA = isAsymmetric(a), |
| |
2354
| + asymmetricB = isAsymmetric(b); |
| |
2355
| + |
| |
2356
| + if (asymmetricA && asymmetricB) { |
| |
2357
| + return undefined; |
| |
2358
| + } |
| |
2359
| + |
| |
2360
| + if (asymmetricA) { |
| |
2361
| + return a.asymmetricMatch(b); |
| |
2362
| + } |
| |
2363
| + |
| |
2364
| + if (asymmetricB) { |
| |
2365
| + return b.asymmetricMatch(a); |
| |
2366
| + } |
| |
2367
| + } |
| |
2368
| + |
| |
2369
| + // Equality function lovingly adapted from isEqual in |
| |
2370
| + // [Underscore](http://underscorejs.org) |
| |
2371
| + function eq(a, b, aStack, bStack, customTesters) { |
| |
2372
| + var result = true; |
| |
2373
| + |
| |
2374
| + var asymmetricResult = asymmetricMatch(a, b); |
| |
2375
| + if (!j$.util.isUndefined(asymmetricResult)) { |
| |
2376
| + return asymmetricResult; |
| |
2377
| + } |
| |
2378
| + |
| |
2379
| + for (var i = 0; i < customTesters.length; i++) { |
| |
2380
| + var customTesterResult = customTesters[i](a, b); |
| |
2381
| + if (!j$.util.isUndefined(customTesterResult)) { |
| |
2382
| + return customTesterResult; |
| |
2383
| + } |
| |
2384
| + } |
| |
2385
| + |
| |
2386
| + if (a instanceof Error && b instanceof Error) { |
| |
2387
| + return a.message == b.message; |
| |
2388
| + } |
| |
2389
| + |
| |
2390
| + // Identical objects are equal. `0 === -0`, but they aren't identical. |
| |
2391
| + // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal). |
| |
2392
| + if (a === b) { return a !== 0 || 1 / a == 1 / b; } |
| |
2393
| + // A strict comparison is necessary because `null == undefined`. |
| |
2394
| + if (a === null || b === null) { return a === b; } |
| |
2395
| + var className = Object.prototype.toString.call(a); |
| |
2396
| + if (className != Object.prototype.toString.call(b)) { return false; } |
| |
2397
| + switch (className) { |
| |
2398
| + // Strings, numbers, dates, and booleans are compared by value. |
| |
2399
| + case '[object String]': |
| |
2400
| + // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is |
| |
2401
| + // equivalent to `new String("5")`. |
| |
2402
| + return a == String(b); |
| |
2403
| + case '[object Number]': |
| |
2404
| + // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for |
| |
2405
| + // other numeric values. |
| |
2406
| + return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b); |
| |
2407
| + case '[object Date]': |
| |
2408
| + case '[object Boolean]': |
| |
2409
| + // Coerce dates and booleans to numeric primitive values. Dates are compared by their |
| |
2410
| + // millisecond representations. Note that invalid dates with millisecond representations |
| |
2411
| + // of `NaN` are not equivalent. |
| |
2412
| + return +a == +b; |
| |
2413
| + // RegExps are compared by their source patterns and flags. |
| |
2414
| + case '[object RegExp]': |
| |
2415
| + return a.source == b.source && |
| |
2416
| + a.global == b.global && |
| |
2417
| + a.multiline == b.multiline && |
| |
2418
| + a.ignoreCase == b.ignoreCase; |
| |
2419
| + } |
| |
2420
| + if (typeof a != 'object' || typeof b != 'object') { return false; } |
| |
2421
| + |
| |
2422
| + var aIsDomNode = j$.isDomNode(a); |
| |
2423
| + var bIsDomNode = j$.isDomNode(b); |
| |
2424
| + if (aIsDomNode && bIsDomNode) { |
| |
2425
| + // At first try to use DOM3 method isEqualNode |
| |
2426
| + if (a.isEqualNode) { |
| |
2427
| + return a.isEqualNode(b); |
| |
2428
| + } |
| |
2429
| + // IE8 doesn't support isEqualNode, try to use outerHTML && innerText |
| |
2430
| + var aIsElement = a instanceof Element; |
| |
2431
| + var bIsElement = b instanceof Element; |
| |
2432
| + if (aIsElement && bIsElement) { |
| |
2433
| + return a.outerHTML == b.outerHTML; |
| |
2434
| + } |
| |
2435
| + if (aIsElement || bIsElement) { |
| |
2436
| + return false; |
| |
2437
| + } |
| |
2438
| + return a.innerText == b.innerText && a.textContent == b.textContent; |
| |
2439
| + } |
| |
2440
| + if (aIsDomNode || bIsDomNode) { |
| |
2441
| + return false; |
| |
2442
| + } |
| |
2443
| + |
| |
2444
| + // Assume equality for cyclic structures. The algorithm for detecting cyclic |
| |
2445
| + // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`. |
| |
2446
| + var length = aStack.length; |
| |
2447
| + while (length--) { |
| |
2448
| + // Linear search. Performance is inversely proportional to the number of |
| |
2449
| + // unique nested structures. |
| |
2450
| + if (aStack[length] == a) { return bStack[length] == b; } |
| |
2451
| + } |
| |
2452
| + // Add the first object to the stack of traversed objects. |
| |
2453
| + aStack.push(a); |
| |
2454
| + bStack.push(b); |
| |
2455
| + var size = 0; |
| |
2456
| + // Recursively compare objects and arrays. |
| |
2457
| + // Compare array lengths to determine if a deep comparison is necessary. |
| |
2458
| + if (className == '[object Array]' && a.length !== b.length) { |
| |
2459
| + result = false; |
| |
2460
| + } |
| |
2461
| + |
| |
2462
| + if (result) { |
| |
2463
| + // Objects with different constructors are not equivalent, but `Object`s |
| |
2464
| + // from different frames are. |
| |
2465
| + var aCtor = a.constructor, bCtor = b.constructor; |
| |
2466
| + if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) && |
| |
2467
| + isFunction(bCtor) && (bCtor instanceof bCtor))) { |
| |
2468
| + return false; |
| |
2469
| + } |
| |
2470
| + // Deep compare objects. |
| |
2471
| + for (var key in a) { |
| |
2472
| + if (has(a, key)) { |
| |
2473
| + // Count the expected number of properties. |
| |
2474
| + size++; |
| |
2475
| + // Deep compare each member. |
| |
2476
| + if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; } |
| |
2477
| + } |
| |
2478
| + } |
| |
2479
| + // Ensure that both objects contain the same number of properties. |
| |
2480
| + if (result) { |
| |
2481
| + for (key in b) { |
| |
2482
| + if (has(b, key) && !(size--)) { break; } |
| |
2483
| + } |
| |
2484
| + result = !size; |
| |
2485
| + } |
| |
2486
| + } |
| |
2487
| + // Remove the first object from the stack of traversed objects. |
| |
2488
| + aStack.pop(); |
| |
2489
| + bStack.pop(); |
| |
2490
| + |
| |
2491
| + return result; |
| |
2492
| + |
| |
2493
| + function has(obj, key) { |
| |
2494
| + return Object.prototype.hasOwnProperty.call(obj, key); |
| |
2495
| + } |
| |
2496
| + |
| |
2497
| + function isFunction(obj) { |
| |
2498
| + return typeof obj === 'function'; |
| |
2499
| + } |
| |
2500
| + } |
| |
2501
| +}; |
| |
2502
| + |
| |
2503
| +getJasmineRequireObj().toBe = function() { |
| |
2504
| + function toBe() { |
| |
2505
| + return { |
| |
2506
| + compare: function(actual, expected) { |
| |
2507
| + return { |
| |
2508
| + pass: actual === expected |
| |
2509
| + }; |
| |
2510
| + } |
| |
2511
| + }; |
| |
2512
| + } |
| |
2513
| + |
| |
2514
| + return toBe; |
| |
2515
| +}; |
| |
2516
| + |
| |
2517
| +getJasmineRequireObj().toBeCloseTo = function() { |
| |
2518
| + |
| |
2519
| + function toBeCloseTo() { |
| |
2520
| + return { |
| |
2521
| + compare: function(actual, expected, precision) { |
| |
2522
| + if (precision !== 0) { |
| |
2523
| + precision = precision || 2; |
| |
2524
| + } |
| |
2525
| + |
| |
2526
| + return { |
| |
2527
| + pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2) |
| |
2528
| + }; |
| |
2529
| + } |
| |
2530
| + }; |
| |
2531
| + } |
| |
2532
| + |
| |
2533
| + return toBeCloseTo; |
| |
2534
| +}; |
| |
2535
| + |
| |
2536
| +getJasmineRequireObj().toBeDefined = function() { |
| |
2537
| + function toBeDefined() { |
| |
2538
| + return { |
| |
2539
| + compare: function(actual) { |
| |
2540
| + return { |
| |
2541
| + pass: (void 0 !== actual) |
| |
2542
| + }; |
| |
2543
| + } |
| |
2544
| + }; |
| |
2545
| + } |
| |
2546
| + |
| |
2547
| + return toBeDefined; |
| |
2548
| +}; |
| |
2549
| + |
| |
2550
| +getJasmineRequireObj().toBeFalsy = function() { |
| |
2551
| + function toBeFalsy() { |
| |
2552
| + return { |
| |
2553
| + compare: function(actual) { |
| |
2554
| + return { |
| |
2555
| + pass: !!!actual |
| |
2556
| + }; |
| |
2557
| + } |
| |
2558
| + }; |
| |
2559
| + } |
| |
2560
| + |
| |
2561
| + return toBeFalsy; |
| |
2562
| +}; |
| |
2563
| + |
| |
2564
| +getJasmineRequireObj().toBeGreaterThan = function() { |
| |
2565
| + |
| |
2566
| + function toBeGreaterThan() { |
| |
2567
| + return { |
| |
2568
| + compare: function(actual, expected) { |
| |
2569
| + return { |
| |
2570
| + pass: actual > expected |
| |
2571
| + }; |
| |
2572
| + } |
| |
2573
| + }; |
| |
2574
| + } |
| |
2575
| + |
| |
2576
| + return toBeGreaterThan; |
| |
2577
| +}; |
| |
2578
| + |
| |
2579
| + |
| |
2580
| +getJasmineRequireObj().toBeLessThan = function() { |
| |
2581
| + function toBeLessThan() { |
| |
2582
| + return { |
| |
2583
| + |
| |
2584
| + compare: function(actual, expected) { |
| |
2585
| + return { |
| |
2586
| + pass: actual < expected |
| |
2587
| + }; |
| |
2588
| + } |
| |
2589
| + }; |
| |
2590
| + } |
| |
2591
| + |
| |
2592
| + return toBeLessThan; |
| |
2593
| +}; |
| |
2594
| +getJasmineRequireObj().toBeNaN = function(j$) { |
| |
2595
| + |
| |
2596
| + function toBeNaN() { |
| |
2597
| + return { |
| |
2598
| + compare: function(actual) { |
| |
2599
| + var result = { |
| |
2600
| + pass: (actual !== actual) |
| |
2601
| + }; |
| |
2602
| + |
| |
2603
| + if (result.pass) { |
| |
2604
| + result.message = 'Expected actual not to be NaN.'; |
| |
2605
| + } else { |
| |
2606
| + result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; }; |
| |
2607
| + } |
| |
2608
| + |
| |
2609
| + return result; |
| |
2610
| + } |
| |
2611
| + }; |
| |
2612
| + } |
| |
2613
| + |
| |
2614
| + return toBeNaN; |
| |
2615
| +}; |
| |
2616
| + |
| |
2617
| +getJasmineRequireObj().toBeNull = function() { |
| |
2618
| + |
| |
2619
| + function toBeNull() { |
| |
2620
| + return { |
| |
2621
| + compare: function(actual) { |
| |
2622
| + return { |
| |
2623
| + pass: actual === null |
| |
2624
| + }; |
| |
2625
| + } |
| |
2626
| + }; |
| |
2627
| + } |
| |
2628
| + |
| |
2629
| + return toBeNull; |
| |
2630
| +}; |
| |
2631
| + |
| |
2632
| +getJasmineRequireObj().toBeTruthy = function() { |
| |
2633
| + |
| |
2634
| + function toBeTruthy() { |
| |
2635
| + return { |
| |
2636
| + compare: function(actual) { |
| |
2637
| + return { |
| |
2638
| + pass: !!actual |
| |
2639
| + }; |
| |
2640
| + } |
| |
2641
| + }; |
| |
2642
| + } |
| |
2643
| + |
| |
2644
| + return toBeTruthy; |
| |
2645
| +}; |
| |
2646
| + |
| |
2647
| +getJasmineRequireObj().toBeUndefined = function() { |
| |
2648
| + |
| |
2649
| + function toBeUndefined() { |
| |
2650
| + return { |
| |
2651
| + compare: function(actual) { |
| |
2652
| + return { |
| |
2653
| + pass: void 0 === actual |
| |
2654
| + }; |
| |
2655
| + } |
| |
2656
| + }; |
| |
2657
| + } |
| |
2658
| + |
| |
2659
| + return toBeUndefined; |
| |
2660
| +}; |
| |
2661
| + |
| |
2662
| +getJasmineRequireObj().toContain = function() { |
| |
2663
| + function toContain(util, customEqualityTesters) { |
| |
2664
| + customEqualityTesters = customEqualityTesters || []; |
| |
2665
| + |
| |
2666
| + return { |
| |
2667
| + compare: function(actual, expected) { |
| |
2668
| + |
| |
2669
| + return { |
| |
2670
| + pass: util.contains(actual, expected, customEqualityTesters) |
| |
2671
| + }; |
| |
2672
| + } |
| |
2673
| + }; |
| |
2674
| + } |
| |
2675
| + |
| |
2676
| + return toContain; |
| |
2677
| +}; |
| |
2678
| + |
| |
2679
| +getJasmineRequireObj().toEqual = function() { |
| |
2680
| + |
| |
2681
| + function toEqual(util, customEqualityTesters) { |
| |
2682
| + customEqualityTesters = customEqualityTesters || []; |
| |
2683
| + |
| |
2684
| + return { |
| |
2685
| + compare: function(actual, expected) { |
| |
2686
| + var result = { |
| |
2687
| + pass: false |
| |
2688
| + }; |
| |
2689
| + |
| |
2690
| + result.pass = util.equals(actual, expected, customEqualityTesters); |
| |
2691
| + |
| |
2692
| + return result; |
| |
2693
| + } |
| |
2694
| + }; |
| |
2695
| + } |
| |
2696
| + |
| |
2697
| + return toEqual; |
| |
2698
| +}; |
| |
2699
| + |
| |
2700
| +getJasmineRequireObj().toHaveBeenCalled = function(j$) { |
| |
2701
| + |
| |
2702
| + function toHaveBeenCalled() { |
| |
2703
| + return { |
| |
2704
| + compare: function(actual) { |
| |
2705
| + var result = {}; |
| |
2706
| + |
| |
2707
| + if (!j$.isSpy(actual)) { |
| |
2708
| + throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); |
| |
2709
| + } |
| |
2710
| + |
| |
2711
| + if (arguments.length > 1) { |
| |
2712
| + throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith'); |
| |
2713
| + } |
| |
2714
| + |
| |
2715
| + result.pass = actual.calls.any(); |
| |
2716
| + |
| |
2717
| + result.message = result.pass ? |
| |
2718
| + 'Expected spy ' + actual.and.identity() + ' not to have been called.' : |
| |
2719
| + 'Expected spy ' + actual.and.identity() + ' to have been called.'; |
| |
2720
| + |
| |
2721
| + return result; |
| |
2722
| + } |
| |
2723
| + }; |
| |
2724
| + } |
| |
2725
| + |
| |
2726
| + return toHaveBeenCalled; |
| |
2727
| +}; |
| |
2728
| + |
| |
2729
| +getJasmineRequireObj().toHaveBeenCalledWith = function(j$) { |
| |
2730
| + |
| |
2731
| + function toHaveBeenCalledWith(util, customEqualityTesters) { |
| |
2732
| + return { |
| |
2733
| + compare: function() { |
| |
2734
| + var args = Array.prototype.slice.call(arguments, 0), |
| |
2735
| + actual = args[0], |
| |
2736
| + expectedArgs = args.slice(1), |
| |
2737
| + result = { pass: false }; |
| |
2738
| + |
| |
2739
| + if (!j$.isSpy(actual)) { |
| |
2740
| + throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.'); |
| |
2741
| + } |
| |
2742
| + |
| |
2743
| + if (!actual.calls.any()) { |
| |
2744
| + result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; }; |
| |
2745
| + return result; |
| |
2746
| + } |
| |
2747
| + |
| |
2748
| + if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) { |
| |
2749
| + result.pass = true; |
| |
2750
| + result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; }; |
| |
2751
| + } else { |
| |
2752
| + result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but actual calls were ' + j$.pp(actual.calls.allArgs()).replace(/^\[ | \]$/g, '') + '.'; }; |
| |
2753
| + } |
| |
2754
| + |
| |
2755
| + return result; |
| |
2756
| + } |
| |
2757
| + }; |
| |
2758
| + } |
| |
2759
| + |
| |
2760
| + return toHaveBeenCalledWith; |
| |
2761
| +}; |
| |
2762
| + |
| |
2763
| +getJasmineRequireObj().toMatch = function(j$) { |
| |
2764
| + |
| |
2765
| + function toMatch() { |
| |
2766
| + return { |
| |
2767
| + compare: function(actual, expected) { |
| |
2768
| + if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) { |
| |
2769
| + throw new Error('Expected is not a String or a RegExp'); |
| |
2770
| + } |
| |
2771
| + |
| |
2772
| + var regexp = new RegExp(expected); |
| |
2773
| + |
| |
2774
| + return { |
| |
2775
| + pass: regexp.test(actual) |
| |
2776
| + }; |
| |
2777
| + } |
| |
2778
| + }; |
| |
2779
| + } |
| |
2780
| + |
| |
2781
| + return toMatch; |
| |
2782
| +}; |
| |
2783
| + |
| |
2784
| +getJasmineRequireObj().toThrow = function(j$) { |
| |
2785
| + |
| |
2786
| + function toThrow(util) { |
| |
2787
| + return { |
| |
2788
| + compare: function(actual, expected) { |
| |
2789
| + var result = { pass: false }, |
| |
2790
| + threw = false, |
| |
2791
| + thrown; |
| |
2792
| + |
| |
2793
| + if (typeof actual != 'function') { |
| |
2794
| + throw new Error('Actual is not a Function'); |
| |
2795
| + } |
| |
2796
| + |
| |
2797
| + try { |
| |
2798
| + actual(); |
| |
2799
| + } catch (e) { |
| |
2800
| + threw = true; |
| |
2801
| + thrown = e; |
| |
2802
| + } |
| |
2803
| + |
| |
2804
| + if (!threw) { |
| |
2805
| + result.message = 'Expected function to throw an exception.'; |
| |
2806
| + return result; |
| |
2807
| + } |
| |
2808
| + |
| |
2809
| + if (arguments.length == 1) { |
| |
2810
| + result.pass = true; |
| |
2811
| + result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; }; |
| |
2812
| + |
| |
2813
| + return result; |
| |
2814
| + } |
| |
2815
| + |
| |
2816
| + if (util.equals(thrown, expected)) { |
| |
2817
| + result.pass = true; |
| |
2818
| + result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; }; |
| |
2819
| + } else { |
| |
2820
| + result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; }; |
| |
2821
| + } |
| |
2822
| + |
| |
2823
| + return result; |
| |
2824
| + } |
| |
2825
| + }; |
| |
2826
| + } |
| |
2827
| + |
| |
2828
| + return toThrow; |
| |
2829
| +}; |
| |
2830
| + |
| |
2831
| +getJasmineRequireObj().toThrowError = function(j$) { |
| |
2832
| + function toThrowError (util) { |
| |
2833
| + return { |
| |
2834
| + compare: function(actual) { |
| |
2835
| + var threw = false, |
| |
2836
| + pass = {pass: true}, |
| |
2837
| + fail = {pass: false}, |
| |
2838
| + thrown; |
| |
2839
| + |
| |
2840
| + if (typeof actual != 'function') { |
| |
2841
| + throw new Error('Actual is not a Function'); |
| |
2842
| + } |
| |
2843
| + |
| |
2844
| + var errorMatcher = getMatcher.apply(null, arguments); |
| |
2845
| + |
| |
2846
| + try { |
| |
2847
| + actual(); |
| |
2848
| + } catch (e) { |
| |
2849
| + threw = true; |
| |
2850
| + thrown = e; |
| |
2851
| + } |
| |
2852
| + |
| |
2853
| + if (!threw) { |
| |
2854
| + fail.message = 'Expected function to throw an Error.'; |
| |
2855
| + return fail; |
| |
2856
| + } |
| |
2857
| + |
| |
2858
| + if (!(thrown instanceof Error)) { |
| |
2859
| + fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; }; |
| |
2860
| + return fail; |
| |
2861
| + } |
| |
2862
| + |
| |
2863
| + if (errorMatcher.hasNoSpecifics()) { |
| |
2864
| + pass.message = 'Expected function not to throw an Error, but it threw ' + j$.fnNameFor(thrown) + '.'; |
| |
2865
| + return pass; |
| |
2866
| + } |
| |
2867
| + |
| |
2868
| + if (errorMatcher.matches(thrown)) { |
| |
2869
| + pass.message = function() { |
| |
2870
| + return 'Expected function not to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + '.'; |
| |
2871
| + }; |
| |
2872
| + return pass; |
| |
2873
| + } else { |
| |
2874
| + fail.message = function() { |
| |
2875
| + return 'Expected function to throw ' + errorMatcher.errorTypeDescription + errorMatcher.messageDescription() + |
| |
2876
| + ', but it threw ' + errorMatcher.thrownDescription(thrown) + '.'; |
| |
2877
| + }; |
| |
2878
| + return fail; |
| |
2879
| + } |
| |
2880
| + } |
| |
2881
| + }; |
| |
2882
| + |
| |
2883
| + function getMatcher() { |
| |
2884
| + var expected = null, |
| |
2885
| + errorType = null; |
| |
2886
| + |
| |
2887
| + if (arguments.length == 2) { |
| |
2888
| + expected = arguments[1]; |
| |
2889
| + if (isAnErrorType(expected)) { |
| |
2890
| + errorType = expected; |
| |
2891
| + expected = null; |
| |
2892
| + } |
| |
2893
| + } else if (arguments.length > 2) { |
| |
2894
| + errorType = arguments[1]; |
| |
2895
| + expected = arguments[2]; |
| |
2896
| + if (!isAnErrorType(errorType)) { |
| |
2897
| + throw new Error('Expected error type is not an Error.'); |
| |
2898
| + } |
| |
2899
| + } |
| |
2900
| + |
| |
2901
| + if (expected && !isStringOrRegExp(expected)) { |
| |
2902
| + if (errorType) { |
| |
2903
| + throw new Error('Expected error message is not a string or RegExp.'); |
| |
2904
| + } else { |
| |
2905
| + throw new Error('Expected is not an Error, string, or RegExp.'); |
| |
2906
| + } |
| |
2907
| + } |
| |
2908
| + |
| |
2909
| + function messageMatch(message) { |
| |
2910
| + if (typeof expected == 'string') { |
| |
2911
| + return expected == message; |
| |
2912
| + } else { |
| |
2913
| + return expected.test(message); |
| |
2914
| + } |
| |
2915
| + } |
| |
2916
| + |
| |
2917
| + return { |
| |
2918
| + errorTypeDescription: errorType ? j$.fnNameFor(errorType) : 'an exception', |
| |
2919
| + thrownDescription: function(thrown) { |
| |
2920
| + var thrownName = errorType ? j$.fnNameFor(thrown.constructor) : 'an exception', |
| |
2921
| + thrownMessage = ''; |
| |
2922
| + |
| |
2923
| + if (expected) { |
| |
2924
| + thrownMessage = ' with message ' + j$.pp(thrown.message); |
| |
2925
| + } |
| |
2926
| + |
| |
2927
| + return thrownName + thrownMessage; |
| |
2928
| + }, |
| |
2929
| + messageDescription: function() { |
| |
2930
| + if (expected === null) { |
| |
2931
| + return ''; |
| |
2932
| + } else if (expected instanceof RegExp) { |
| |
2933
| + return ' with a message matching ' + j$.pp(expected); |
| |
2934
| + } else { |
| |
2935
| + return ' with message ' + j$.pp(expected); |
| |
2936
| + } |
| |
2937
| + }, |
| |
2938
| + hasNoSpecifics: function() { |
| |
2939
| + return expected === null && errorType === null; |
| |
2940
| + }, |
| |
2941
| + matches: function(error) { |
| |
2942
| + return (errorType === null || error.constructor === errorType) && |
| |
2943
| + (expected === null || messageMatch(error.message)); |
| |
2944
| + } |
| |
2945
| + }; |
| |
2946
| + } |
| |
2947
| + |
| |
2948
| + function isStringOrRegExp(potential) { |
| |
2949
| + return potential instanceof RegExp || (typeof potential == 'string'); |
| |
2950
| + } |
| |
2951
| + |
| |
2952
| + function isAnErrorType(type) { |
| |
2953
| + if (typeof type !== 'function') { |
| |
2954
| + return false; |
| |
2955
| + } |
| |
2956
| + |
| |
2957
| + var Surrogate = function() {}; |
| |
2958
| + Surrogate.prototype = type.prototype; |
| |
2959
| + return (new Surrogate()) instanceof Error; |
| |
2960
| + } |
| |
2961
| + } |
| |
2962
| + |
| |
2963
| + return toThrowError; |
| |
2964
| +}; |
| |
2965
| + |
| |
2966
| +getJasmineRequireObj().interface = function(jasmine, env) { |
| |
2967
| + var jasmineInterface = { |
| |
2968
| + describe: function(description, specDefinitions) { |
| |
2969
| + return env.describe(description, specDefinitions); |
| |
2970
| + }, |
| |
2971
| + |
| |
2972
| + xdescribe: function(description, specDefinitions) { |
| |
2973
| + return env.xdescribe(description, specDefinitions); |
| |
2974
| + }, |
| |
2975
| + |
| |
2976
| + fdescribe: function(description, specDefinitions) { |
| |
2977
| + return env.fdescribe(description, specDefinitions); |
| |
2978
| + }, |
| |
2979
| + |
| |
2980
| + it: function() { |
| |
2981
| + return env.it.apply(env, arguments); |
| |
2982
| + }, |
| |
2983
| + |
| |
2984
| + xit: function() { |
| |
2985
| + return env.xit.apply(env, arguments); |
| |
2986
| + }, |
| |
2987
| + |
| |
2988
| + fit: function() { |
| |
2989
| + return env.fit.apply(env, arguments); |
| |
2990
| + }, |
| |
2991
| + |
| |
2992
| + beforeEach: function() { |
| |
2993
| + return env.beforeEach.apply(env, arguments); |
| |
2994
| + }, |
| |
2995
| + |
| |
2996
| + afterEach: function() { |
| |
2997
| + return env.afterEach.apply(env, arguments); |
| |
2998
| + }, |
| |
2999
| + |
| |
3000
| + beforeAll: function() { |
| |
3001
| + return env.beforeAll.apply(env, arguments); |
| |
3002
| + }, |
| |
3003
| + |
| |
3004
| + afterAll: function() { |
| |
3005
| + return env.afterAll.apply(env, arguments); |
| |
3006
| + }, |
| |
3007
| + |
| |
3008
| + expect: function(actual) { |
| |
3009
| + return env.expect(actual); |
| |
3010
| + }, |
| |
3011
| + |
| |
3012
| + pending: function() { |
| |
3013
| + return env.pending.apply(env, arguments); |
| |
3014
| + }, |
| |
3015
| + |
| |
3016
| + fail: function() { |
| |
3017
| + return env.fail.apply(env, arguments); |
| |
3018
| + }, |
| |
3019
| + |
| |
3020
| + spyOn: function(obj, methodName) { |
| |
3021
| + return env.spyOn(obj, methodName); |
| |
3022
| + }, |
| |
3023
| + |
| |
3024
| + jsApiReporter: new jasmine.JsApiReporter({ |
| |
3025
| + timer: new jasmine.Timer() |
| |
3026
| + }), |
| |
3027
| + |
| |
3028
| + jasmine: jasmine |
| |
3029
| + }; |
| |
3030
| + |
| |
3031
| + jasmine.addCustomEqualityTester = function(tester) { |
| |
3032
| + env.addCustomEqualityTester(tester); |
| |
3033
| + }; |
| |
3034
| + |
| |
3035
| + jasmine.addMatchers = function(matchers) { |
| |
3036
| + return env.addMatchers(matchers); |
| |
3037
| + }; |
| |
3038
| + |
| |
3039
| + jasmine.clock = function() { |
| |
3040
| + return env.clock; |
| |
3041
| + }; |
| |
3042
| + |
| |
3043
| + return jasmineInterface; |
| |
3044
| +}; |
| |
3045
| + |
| |
3046
| +getJasmineRequireObj().version = function() { |
| |
3047
| + return '2.2.0'; |
| |
3048
| +}; |