Nessuna descrizione

jasmine.js 67KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593
  1. /*
  2. Copyright (c) 2008-2014 Pivotal Labs
  3. Permission is hereby granted, free of charge, to any person obtaining
  4. a copy of this software and associated documentation files (the
  5. "Software"), to deal in the Software without restriction, including
  6. without limitation the rights to use, copy, modify, merge, publish,
  7. distribute, sublicense, and/or sell copies of the Software, and to
  8. permit persons to whom the Software is furnished to do so, subject to
  9. the following conditions:
  10. The above copyright notice and this permission notice shall be
  11. included in all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  13. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  14. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  15. NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  16. LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  17. OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  18. WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  19. */
  20. function getJasmineRequireObj() {
  21. if (typeof module !== 'undefined' && module.exports) {
  22. return exports;
  23. } else {
  24. window.jasmineRequire = window.jasmineRequire || {};
  25. return window.jasmineRequire;
  26. }
  27. }
  28. getJasmineRequireObj().core = function(jRequire) {
  29. var j$ = {};
  30. jRequire.base(j$);
  31. j$.util = jRequire.util();
  32. j$.Any = jRequire.Any();
  33. j$.CallTracker = jRequire.CallTracker();
  34. j$.MockDate = jRequire.MockDate();
  35. j$.Clock = jRequire.Clock();
  36. j$.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler();
  37. j$.Env = jRequire.Env(j$);
  38. j$.ExceptionFormatter = jRequire.ExceptionFormatter();
  39. j$.Expectation = jRequire.Expectation();
  40. j$.buildExpectationResult = jRequire.buildExpectationResult();
  41. j$.JsApiReporter = jRequire.JsApiReporter();
  42. j$.matchersUtil = jRequire.matchersUtil(j$);
  43. j$.ObjectContaining = jRequire.ObjectContaining(j$);
  44. j$.pp = jRequire.pp(j$);
  45. j$.QueueRunner = jRequire.QueueRunner(j$);
  46. j$.ReportDispatcher = jRequire.ReportDispatcher();
  47. j$.Spec = jRequire.Spec(j$);
  48. j$.SpyStrategy = jRequire.SpyStrategy();
  49. j$.Suite = jRequire.Suite();
  50. j$.Timer = jRequire.Timer();
  51. j$.version = jRequire.version();
  52. j$.matchers = jRequire.requireMatchers(jRequire, j$);
  53. return j$;
  54. };
  55. getJasmineRequireObj().requireMatchers = function(jRequire, j$) {
  56. var availableMatchers = [
  57. 'toBe',
  58. 'toBeCloseTo',
  59. 'toBeDefined',
  60. 'toBeFalsy',
  61. 'toBeGreaterThan',
  62. 'toBeLessThan',
  63. 'toBeNaN',
  64. 'toBeNull',
  65. 'toBeTruthy',
  66. 'toBeUndefined',
  67. 'toContain',
  68. 'toEqual',
  69. 'toHaveBeenCalled',
  70. 'toHaveBeenCalledWith',
  71. 'toMatch',
  72. 'toThrow',
  73. 'toThrowError'
  74. ],
  75. matchers = {};
  76. for (var i = 0; i < availableMatchers.length; i++) {
  77. var name = availableMatchers[i];
  78. matchers[name] = jRequire[name](j$);
  79. }
  80. return matchers;
  81. };
  82. getJasmineRequireObj().base = (function (jasmineGlobal) {
  83. if (typeof module !== 'undefined' && module.exports) {
  84. jasmineGlobal = global;
  85. }
  86. return function(j$) {
  87. j$.unimplementedMethod_ = function() {
  88. throw new Error('unimplemented method');
  89. };
  90. j$.MAX_PRETTY_PRINT_DEPTH = 40;
  91. j$.MAX_PRETTY_PRINT_ARRAY_LENGTH = 100;
  92. j$.DEFAULT_TIMEOUT_INTERVAL = 5000;
  93. j$.getGlobal = function() {
  94. return jasmineGlobal;
  95. };
  96. j$.getEnv = function(options) {
  97. var env = j$.currentEnv_ = j$.currentEnv_ || new j$.Env(options);
  98. //jasmine. singletons in here (setTimeout blah blah).
  99. return env;
  100. };
  101. j$.isArray_ = function(value) {
  102. return j$.isA_('Array', value);
  103. };
  104. j$.isString_ = function(value) {
  105. return j$.isA_('String', value);
  106. };
  107. j$.isNumber_ = function(value) {
  108. return j$.isA_('Number', value);
  109. };
  110. j$.isA_ = function(typeName, value) {
  111. return Object.prototype.toString.apply(value) === '[object ' + typeName + ']';
  112. };
  113. j$.isDomNode = function(obj) {
  114. return obj.nodeType > 0;
  115. };
  116. j$.any = function(clazz) {
  117. return new j$.Any(clazz);
  118. };
  119. j$.objectContaining = function(sample) {
  120. return new j$.ObjectContaining(sample);
  121. };
  122. j$.createSpy = function(name, originalFn) {
  123. var spyStrategy = new j$.SpyStrategy({
  124. name: name,
  125. fn: originalFn,
  126. getSpy: function() { return spy; }
  127. }),
  128. callTracker = new j$.CallTracker(),
  129. spy = function() {
  130. callTracker.track({
  131. object: this,
  132. args: Array.prototype.slice.apply(arguments)
  133. });
  134. return spyStrategy.exec.apply(this, arguments);
  135. };
  136. for (var prop in originalFn) {
  137. if (prop === 'and' || prop === 'calls') {
  138. throw new Error('Jasmine spies would overwrite the \'and\' and \'calls\' properties on the object being spied upon');
  139. }
  140. spy[prop] = originalFn[prop];
  141. }
  142. spy.and = spyStrategy;
  143. spy.calls = callTracker;
  144. return spy;
  145. };
  146. j$.isSpy = function(putativeSpy) {
  147. if (!putativeSpy) {
  148. return false;
  149. }
  150. return putativeSpy.and instanceof j$.SpyStrategy &&
  151. putativeSpy.calls instanceof j$.CallTracker;
  152. };
  153. j$.createSpyObj = function(baseName, methodNames) {
  154. if (!j$.isArray_(methodNames) || methodNames.length === 0) {
  155. throw 'createSpyObj requires a non-empty array of method names to create spies for';
  156. }
  157. var obj = {};
  158. for (var i = 0; i < methodNames.length; i++) {
  159. obj[methodNames[i]] = j$.createSpy(baseName + '.' + methodNames[i]);
  160. }
  161. return obj;
  162. };
  163. };
  164. })(this);
  165. getJasmineRequireObj().util = function() {
  166. var util = {};
  167. util.inherit = function(childClass, parentClass) {
  168. var Subclass = function() {
  169. };
  170. Subclass.prototype = parentClass.prototype;
  171. childClass.prototype = new Subclass();
  172. };
  173. util.htmlEscape = function(str) {
  174. if (!str) {
  175. return str;
  176. }
  177. return str.replace(/&/g, '&amp;')
  178. .replace(/</g, '&lt;')
  179. .replace(/>/g, '&gt;');
  180. };
  181. util.argsToArray = function(args) {
  182. var arrayOfArgs = [];
  183. for (var i = 0; i < args.length; i++) {
  184. arrayOfArgs.push(args[i]);
  185. }
  186. return arrayOfArgs;
  187. };
  188. util.isUndefined = function(obj) {
  189. return obj === void 0;
  190. };
  191. util.arrayContains = function(array, search) {
  192. var i = array.length;
  193. while (i--) {
  194. if (array[i] == search) {
  195. return true;
  196. }
  197. }
  198. return false;
  199. };
  200. return util;
  201. };
  202. getJasmineRequireObj().Spec = function(j$) {
  203. function Spec(attrs) {
  204. this.expectationFactory = attrs.expectationFactory;
  205. this.resultCallback = attrs.resultCallback || function() {};
  206. this.id = attrs.id;
  207. this.description = attrs.description || '';
  208. this.fn = attrs.fn;
  209. this.beforeFns = attrs.beforeFns || function() { return []; };
  210. this.afterFns = attrs.afterFns || function() { return []; };
  211. this.onStart = attrs.onStart || function() {};
  212. this.exceptionFormatter = attrs.exceptionFormatter || function() {};
  213. this.getSpecName = attrs.getSpecName || function() { return ''; };
  214. this.expectationResultFactory = attrs.expectationResultFactory || function() { };
  215. this.queueRunnerFactory = attrs.queueRunnerFactory || function() {};
  216. this.catchingExceptions = attrs.catchingExceptions || function() { return true; };
  217. if (!this.fn) {
  218. this.pend();
  219. }
  220. this.result = {
  221. id: this.id,
  222. description: this.description,
  223. fullName: this.getFullName(),
  224. failedExpectations: [],
  225. passedExpectations: []
  226. };
  227. }
  228. Spec.prototype.addExpectationResult = function(passed, data) {
  229. var expectationResult = this.expectationResultFactory(data);
  230. if (passed) {
  231. this.result.passedExpectations.push(expectationResult);
  232. } else {
  233. this.result.failedExpectations.push(expectationResult);
  234. }
  235. };
  236. Spec.prototype.expect = function(actual) {
  237. return this.expectationFactory(actual, this);
  238. };
  239. Spec.prototype.execute = function(onComplete) {
  240. var self = this;
  241. this.onStart(this);
  242. if (this.markedPending || this.disabled) {
  243. complete();
  244. return;
  245. }
  246. var allFns = this.beforeFns().concat(this.fn).concat(this.afterFns());
  247. this.queueRunnerFactory({
  248. fns: allFns,
  249. onException: onException,
  250. onComplete: complete,
  251. enforceTimeout: function() { return true; }
  252. });
  253. function onException(e) {
  254. if (Spec.isPendingSpecException(e)) {
  255. self.pend();
  256. return;
  257. }
  258. self.addExpectationResult(false, {
  259. matcherName: '',
  260. passed: false,
  261. expected: '',
  262. actual: '',
  263. error: e
  264. });
  265. }
  266. function complete() {
  267. self.result.status = self.status();
  268. self.resultCallback(self.result);
  269. if (onComplete) {
  270. onComplete();
  271. }
  272. }
  273. };
  274. Spec.prototype.disable = function() {
  275. this.disabled = true;
  276. };
  277. Spec.prototype.pend = function() {
  278. this.markedPending = true;
  279. };
  280. Spec.prototype.status = function() {
  281. if (this.disabled) {
  282. return 'disabled';
  283. }
  284. if (this.markedPending) {
  285. return 'pending';
  286. }
  287. if (this.result.failedExpectations.length > 0) {
  288. return 'failed';
  289. } else {
  290. return 'passed';
  291. }
  292. };
  293. Spec.prototype.getFullName = function() {
  294. return this.getSpecName(this);
  295. };
  296. Spec.pendingSpecExceptionMessage = '=> marked Pending';
  297. Spec.isPendingSpecException = function(e) {
  298. return !!(e && e.toString && e.toString().indexOf(Spec.pendingSpecExceptionMessage) !== -1);
  299. };
  300. return Spec;
  301. };
  302. if (typeof window == void 0 && typeof exports == 'object') {
  303. exports.Spec = jasmineRequire.Spec;
  304. }
  305. getJasmineRequireObj().Env = function(j$) {
  306. function Env(options) {
  307. options = options || {};
  308. var self = this;
  309. var global = options.global || j$.getGlobal();
  310. var totalSpecsDefined = 0;
  311. var catchExceptions = true;
  312. var realSetTimeout = j$.getGlobal().setTimeout;
  313. var realClearTimeout = j$.getGlobal().clearTimeout;
  314. this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler(), new j$.MockDate(global));
  315. var runnableLookupTable = {};
  316. var spies = [];
  317. var currentSpec = null;
  318. var currentSuite = null;
  319. var reporter = new j$.ReportDispatcher([
  320. 'jasmineStarted',
  321. 'jasmineDone',
  322. 'suiteStarted',
  323. 'suiteDone',
  324. 'specStarted',
  325. 'specDone'
  326. ]);
  327. this.specFilter = function() {
  328. return true;
  329. };
  330. var equalityTesters = [];
  331. var customEqualityTesters = [];
  332. this.addCustomEqualityTester = function(tester) {
  333. customEqualityTesters.push(tester);
  334. };
  335. j$.Expectation.addCoreMatchers(j$.matchers);
  336. var nextSpecId = 0;
  337. var getNextSpecId = function() {
  338. return 'spec' + nextSpecId++;
  339. };
  340. var nextSuiteId = 0;
  341. var getNextSuiteId = function() {
  342. return 'suite' + nextSuiteId++;
  343. };
  344. var expectationFactory = function(actual, spec) {
  345. return j$.Expectation.Factory({
  346. util: j$.matchersUtil,
  347. customEqualityTesters: customEqualityTesters,
  348. actual: actual,
  349. addExpectationResult: addExpectationResult
  350. });
  351. function addExpectationResult(passed, result) {
  352. return spec.addExpectationResult(passed, result);
  353. }
  354. };
  355. var specStarted = function(spec) {
  356. currentSpec = spec;
  357. reporter.specStarted(spec.result);
  358. };
  359. var beforeFns = function(suite) {
  360. return function() {
  361. var befores = [];
  362. while(suite) {
  363. befores = befores.concat(suite.beforeFns);
  364. suite = suite.parentSuite;
  365. }
  366. return befores.reverse();
  367. };
  368. };
  369. var afterFns = function(suite) {
  370. return function() {
  371. var afters = [];
  372. while(suite) {
  373. afters = afters.concat(suite.afterFns);
  374. suite = suite.parentSuite;
  375. }
  376. return afters;
  377. };
  378. };
  379. var getSpecName = function(spec, suite) {
  380. return suite.getFullName() + ' ' + spec.description;
  381. };
  382. // TODO: we may just be able to pass in the fn instead of wrapping here
  383. var buildExpectationResult = j$.buildExpectationResult,
  384. exceptionFormatter = new j$.ExceptionFormatter(),
  385. expectationResultFactory = function(attrs) {
  386. attrs.messageFormatter = exceptionFormatter.message;
  387. attrs.stackFormatter = exceptionFormatter.stack;
  388. return buildExpectationResult(attrs);
  389. };
  390. // TODO: fix this naming, and here's where the value comes in
  391. this.catchExceptions = function(value) {
  392. catchExceptions = !!value;
  393. return catchExceptions;
  394. };
  395. this.catchingExceptions = function() {
  396. return catchExceptions;
  397. };
  398. var maximumSpecCallbackDepth = 20;
  399. var currentSpecCallbackDepth = 0;
  400. function clearStack(fn) {
  401. currentSpecCallbackDepth++;
  402. if (currentSpecCallbackDepth >= maximumSpecCallbackDepth) {
  403. currentSpecCallbackDepth = 0;
  404. realSetTimeout(fn, 0);
  405. } else {
  406. fn();
  407. }
  408. }
  409. var catchException = function(e) {
  410. return j$.Spec.isPendingSpecException(e) || catchExceptions;
  411. };
  412. var queueRunnerFactory = function(options) {
  413. options.catchException = catchException;
  414. options.clearStack = options.clearStack || clearStack;
  415. options.timer = {setTimeout: realSetTimeout, clearTimeout: realClearTimeout};
  416. new j$.QueueRunner(options).execute();
  417. };
  418. var topSuite = new j$.Suite({
  419. env: this,
  420. id: getNextSuiteId(),
  421. description: 'Jasmine__TopLevel__Suite',
  422. queueRunner: queueRunnerFactory,
  423. resultCallback: function() {} // TODO - hook this up
  424. });
  425. runnableLookupTable[topSuite.id] = topSuite;
  426. currentSuite = topSuite;
  427. this.topSuite = function() {
  428. return topSuite;
  429. };
  430. this.execute = function(runnablesToRun) {
  431. runnablesToRun = runnablesToRun || [topSuite.id];
  432. var allFns = [];
  433. for(var i = 0; i < runnablesToRun.length; i++) {
  434. var runnable = runnableLookupTable[runnablesToRun[i]];
  435. allFns.push((function(runnable) { return function(done) { runnable.execute(done); }; })(runnable));
  436. }
  437. reporter.jasmineStarted({
  438. totalSpecsDefined: totalSpecsDefined
  439. });
  440. queueRunnerFactory({fns: allFns, onComplete: reporter.jasmineDone});
  441. };
  442. this.addReporter = function(reporterToAdd) {
  443. reporter.addReporter(reporterToAdd);
  444. };
  445. this.addMatchers = function(matchersToAdd) {
  446. j$.Expectation.addMatchers(matchersToAdd);
  447. };
  448. this.spyOn = function(obj, methodName) {
  449. if (j$.util.isUndefined(obj)) {
  450. throw new Error('spyOn could not find an object to spy upon for ' + methodName + '()');
  451. }
  452. if (j$.util.isUndefined(obj[methodName])) {
  453. throw new Error(methodName + '() method does not exist');
  454. }
  455. if (obj[methodName] && j$.isSpy(obj[methodName])) {
  456. //TODO?: should this return the current spy? Downside: may cause user confusion about spy state
  457. throw new Error(methodName + ' has already been spied upon');
  458. }
  459. var spy = j$.createSpy(methodName, obj[methodName]);
  460. spies.push({
  461. spy: spy,
  462. baseObj: obj,
  463. methodName: methodName,
  464. originalValue: obj[methodName]
  465. });
  466. obj[methodName] = spy;
  467. return spy;
  468. };
  469. var suiteFactory = function(description) {
  470. var suite = new j$.Suite({
  471. env: self,
  472. id: getNextSuiteId(),
  473. description: description,
  474. parentSuite: currentSuite,
  475. queueRunner: queueRunnerFactory,
  476. onStart: suiteStarted,
  477. resultCallback: function(attrs) {
  478. reporter.suiteDone(attrs);
  479. }
  480. });
  481. runnableLookupTable[suite.id] = suite;
  482. return suite;
  483. };
  484. this.describe = function(description, specDefinitions) {
  485. var suite = suiteFactory(description);
  486. var parentSuite = currentSuite;
  487. parentSuite.addChild(suite);
  488. currentSuite = suite;
  489. var declarationError = null;
  490. try {
  491. specDefinitions.call(suite);
  492. } catch (e) {
  493. declarationError = e;
  494. }
  495. if (declarationError) {
  496. this.it('encountered a declaration exception', function() {
  497. throw declarationError;
  498. });
  499. }
  500. currentSuite = parentSuite;
  501. return suite;
  502. };
  503. this.xdescribe = function(description, specDefinitions) {
  504. var suite = this.describe(description, specDefinitions);
  505. suite.disable();
  506. return suite;
  507. };
  508. var specFactory = function(description, fn, suite) {
  509. totalSpecsDefined++;
  510. var spec = new j$.Spec({
  511. id: getNextSpecId(),
  512. beforeFns: beforeFns(suite),
  513. afterFns: afterFns(suite),
  514. expectationFactory: expectationFactory,
  515. exceptionFormatter: exceptionFormatter,
  516. resultCallback: specResultCallback,
  517. getSpecName: function(spec) {
  518. return getSpecName(spec, suite);
  519. },
  520. onStart: specStarted,
  521. description: description,
  522. expectationResultFactory: expectationResultFactory,
  523. queueRunnerFactory: queueRunnerFactory,
  524. fn: fn
  525. });
  526. runnableLookupTable[spec.id] = spec;
  527. if (!self.specFilter(spec)) {
  528. spec.disable();
  529. }
  530. return spec;
  531. function removeAllSpies() {
  532. for (var i = 0; i < spies.length; i++) {
  533. var spyEntry = spies[i];
  534. spyEntry.baseObj[spyEntry.methodName] = spyEntry.originalValue;
  535. }
  536. spies = [];
  537. }
  538. function specResultCallback(result) {
  539. removeAllSpies();
  540. j$.Expectation.resetMatchers();
  541. customEqualityTesters = [];
  542. currentSpec = null;
  543. reporter.specDone(result);
  544. }
  545. };
  546. var suiteStarted = function(suite) {
  547. reporter.suiteStarted(suite.result);
  548. };
  549. this.it = function(description, fn) {
  550. var spec = specFactory(description, fn, currentSuite);
  551. currentSuite.addChild(spec);
  552. return spec;
  553. };
  554. this.xit = function(description, fn) {
  555. var spec = this.it(description, fn);
  556. spec.pend();
  557. return spec;
  558. };
  559. this.expect = function(actual) {
  560. if (!currentSpec) {
  561. throw new Error('\'expect\' was used when there was no current spec, this could be because an asynchronous test timed out');
  562. }
  563. return currentSpec.expect(actual);
  564. };
  565. this.beforeEach = function(beforeEachFunction) {
  566. currentSuite.beforeEach(beforeEachFunction);
  567. };
  568. this.afterEach = function(afterEachFunction) {
  569. currentSuite.afterEach(afterEachFunction);
  570. };
  571. this.pending = function() {
  572. throw j$.Spec.pendingSpecExceptionMessage;
  573. };
  574. }
  575. return Env;
  576. };
  577. getJasmineRequireObj().JsApiReporter = function() {
  578. var noopTimer = {
  579. start: function(){},
  580. elapsed: function(){ return 0; }
  581. };
  582. function JsApiReporter(options) {
  583. var timer = options.timer || noopTimer,
  584. status = 'loaded';
  585. this.started = false;
  586. this.finished = false;
  587. this.jasmineStarted = function() {
  588. this.started = true;
  589. status = 'started';
  590. timer.start();
  591. };
  592. var executionTime;
  593. this.jasmineDone = function() {
  594. this.finished = true;
  595. executionTime = timer.elapsed();
  596. status = 'done';
  597. };
  598. this.status = function() {
  599. return status;
  600. };
  601. var suites = {};
  602. this.suiteStarted = function(result) {
  603. storeSuite(result);
  604. };
  605. this.suiteDone = function(result) {
  606. storeSuite(result);
  607. };
  608. function storeSuite(result) {
  609. suites[result.id] = result;
  610. }
  611. this.suites = function() {
  612. return suites;
  613. };
  614. var specs = [];
  615. this.specStarted = function(result) { };
  616. this.specDone = function(result) {
  617. specs.push(result);
  618. };
  619. this.specResults = function(index, length) {
  620. return specs.slice(index, index + length);
  621. };
  622. this.specs = function() {
  623. return specs;
  624. };
  625. this.executionTime = function() {
  626. return executionTime;
  627. };
  628. }
  629. return JsApiReporter;
  630. };
  631. getJasmineRequireObj().Any = function() {
  632. function Any(expectedObject) {
  633. this.expectedObject = expectedObject;
  634. }
  635. Any.prototype.jasmineMatches = function(other) {
  636. if (this.expectedObject == String) {
  637. return typeof other == 'string' || other instanceof String;
  638. }
  639. if (this.expectedObject == Number) {
  640. return typeof other == 'number' || other instanceof Number;
  641. }
  642. if (this.expectedObject == Function) {
  643. return typeof other == 'function' || other instanceof Function;
  644. }
  645. if (this.expectedObject == Object) {
  646. return typeof other == 'object';
  647. }
  648. if (this.expectedObject == Boolean) {
  649. return typeof other == 'boolean';
  650. }
  651. return other instanceof this.expectedObject;
  652. };
  653. Any.prototype.jasmineToString = function() {
  654. return '<jasmine.any(' + this.expectedObject + ')>';
  655. };
  656. return Any;
  657. };
  658. getJasmineRequireObj().CallTracker = function() {
  659. function CallTracker() {
  660. var calls = [];
  661. this.track = function(context) {
  662. calls.push(context);
  663. };
  664. this.any = function() {
  665. return !!calls.length;
  666. };
  667. this.count = function() {
  668. return calls.length;
  669. };
  670. this.argsFor = function(index) {
  671. var call = calls[index];
  672. return call ? call.args : [];
  673. };
  674. this.all = function() {
  675. return calls;
  676. };
  677. this.allArgs = function() {
  678. var callArgs = [];
  679. for(var i = 0; i < calls.length; i++){
  680. callArgs.push(calls[i].args);
  681. }
  682. return callArgs;
  683. };
  684. this.first = function() {
  685. return calls[0];
  686. };
  687. this.mostRecent = function() {
  688. return calls[calls.length - 1];
  689. };
  690. this.reset = function() {
  691. calls = [];
  692. };
  693. }
  694. return CallTracker;
  695. };
  696. getJasmineRequireObj().Clock = function() {
  697. function Clock(global, delayedFunctionScheduler, mockDate) {
  698. var self = this,
  699. realTimingFunctions = {
  700. setTimeout: global.setTimeout,
  701. clearTimeout: global.clearTimeout,
  702. setInterval: global.setInterval,
  703. clearInterval: global.clearInterval
  704. },
  705. fakeTimingFunctions = {
  706. setTimeout: setTimeout,
  707. clearTimeout: clearTimeout,
  708. setInterval: setInterval,
  709. clearInterval: clearInterval
  710. },
  711. installed = false,
  712. timer;
  713. self.install = function() {
  714. replace(global, fakeTimingFunctions);
  715. timer = fakeTimingFunctions;
  716. installed = true;
  717. return self;
  718. };
  719. self.uninstall = function() {
  720. delayedFunctionScheduler.reset();
  721. mockDate.uninstall();
  722. replace(global, realTimingFunctions);
  723. timer = realTimingFunctions;
  724. installed = false;
  725. };
  726. self.mockDate = function(initialDate) {
  727. mockDate.install(initialDate);
  728. };
  729. self.setTimeout = function(fn, delay, params) {
  730. if (legacyIE()) {
  731. if (arguments.length > 2) {
  732. throw new Error('IE < 9 cannot support extra params to setTimeout without a polyfill');
  733. }
  734. return timer.setTimeout(fn, delay);
  735. }
  736. return Function.prototype.apply.apply(timer.setTimeout, [global, arguments]);
  737. };
  738. self.setInterval = function(fn, delay, params) {
  739. if (legacyIE()) {
  740. if (arguments.length > 2) {
  741. throw new Error('IE < 9 cannot support extra params to setInterval without a polyfill');
  742. }
  743. return timer.setInterval(fn, delay);
  744. }
  745. return Function.prototype.apply.apply(timer.setInterval, [global, arguments]);
  746. };
  747. self.clearTimeout = function(id) {
  748. return Function.prototype.call.apply(timer.clearTimeout, [global, id]);
  749. };
  750. self.clearInterval = function(id) {
  751. return Function.prototype.call.apply(timer.clearInterval, [global, id]);
  752. };
  753. self.tick = function(millis) {
  754. if (installed) {
  755. mockDate.tick(millis);
  756. delayedFunctionScheduler.tick(millis);
  757. } else {
  758. throw new Error('Mock clock is not installed, use jasmine.clock().install()');
  759. }
  760. };
  761. return self;
  762. function legacyIE() {
  763. //if these methods are polyfilled, apply will be present
  764. return !(realTimingFunctions.setTimeout || realTimingFunctions.setInterval).apply;
  765. }
  766. function replace(dest, source) {
  767. for (var prop in source) {
  768. dest[prop] = source[prop];
  769. }
  770. }
  771. function setTimeout(fn, delay) {
  772. return delayedFunctionScheduler.scheduleFunction(fn, delay, argSlice(arguments, 2));
  773. }
  774. function clearTimeout(id) {
  775. return delayedFunctionScheduler.removeFunctionWithId(id);
  776. }
  777. function setInterval(fn, interval) {
  778. return delayedFunctionScheduler.scheduleFunction(fn, interval, argSlice(arguments, 2), true);
  779. }
  780. function clearInterval(id) {
  781. return delayedFunctionScheduler.removeFunctionWithId(id);
  782. }
  783. function argSlice(argsObj, n) {
  784. return Array.prototype.slice.call(argsObj, n);
  785. }
  786. }
  787. return Clock;
  788. };
  789. getJasmineRequireObj().DelayedFunctionScheduler = function() {
  790. function DelayedFunctionScheduler() {
  791. var self = this;
  792. var scheduledLookup = [];
  793. var scheduledFunctions = {};
  794. var currentTime = 0;
  795. var delayedFnCount = 0;
  796. self.tick = function(millis) {
  797. millis = millis || 0;
  798. var endTime = currentTime + millis;
  799. runScheduledFunctions(endTime);
  800. currentTime = endTime;
  801. };
  802. self.scheduleFunction = function(funcToCall, millis, params, recurring, timeoutKey, runAtMillis) {
  803. var f;
  804. if (typeof(funcToCall) === 'string') {
  805. /* jshint evil: true */
  806. f = function() { return eval(funcToCall); };
  807. /* jshint evil: false */
  808. } else {
  809. f = funcToCall;
  810. }
  811. millis = millis || 0;
  812. timeoutKey = timeoutKey || ++delayedFnCount;
  813. runAtMillis = runAtMillis || (currentTime + millis);
  814. var funcToSchedule = {
  815. runAtMillis: runAtMillis,
  816. funcToCall: f,
  817. recurring: recurring,
  818. params: params,
  819. timeoutKey: timeoutKey,
  820. millis: millis
  821. };
  822. if (runAtMillis in scheduledFunctions) {
  823. scheduledFunctions[runAtMillis].push(funcToSchedule);
  824. } else {
  825. scheduledFunctions[runAtMillis] = [funcToSchedule];
  826. scheduledLookup.push(runAtMillis);
  827. scheduledLookup.sort(function (a, b) {
  828. return a - b;
  829. });
  830. }
  831. return timeoutKey;
  832. };
  833. self.removeFunctionWithId = function(timeoutKey) {
  834. for (var runAtMillis in scheduledFunctions) {
  835. var funcs = scheduledFunctions[runAtMillis];
  836. var i = indexOfFirstToPass(funcs, function (func) {
  837. return func.timeoutKey === timeoutKey;
  838. });
  839. if (i > -1) {
  840. if (funcs.length === 1) {
  841. delete scheduledFunctions[runAtMillis];
  842. deleteFromLookup(runAtMillis);
  843. } else {
  844. funcs.splice(i, 1);
  845. }
  846. // intervals get rescheduled when executed, so there's never more
  847. // than a single scheduled function with a given timeoutKey
  848. break;
  849. }
  850. }
  851. };
  852. self.reset = function() {
  853. currentTime = 0;
  854. scheduledLookup = [];
  855. scheduledFunctions = {};
  856. delayedFnCount = 0;
  857. };
  858. return self;
  859. function indexOfFirstToPass(array, testFn) {
  860. var index = -1;
  861. for (var i = 0; i < array.length; ++i) {
  862. if (testFn(array[i])) {
  863. index = i;
  864. break;
  865. }
  866. }
  867. return index;
  868. }
  869. function deleteFromLookup(key) {
  870. var value = Number(key);
  871. var i = indexOfFirstToPass(scheduledLookup, function (millis) {
  872. return millis === value;
  873. });
  874. if (i > -1) {
  875. scheduledLookup.splice(i, 1);
  876. }
  877. }
  878. function reschedule(scheduledFn) {
  879. self.scheduleFunction(scheduledFn.funcToCall,
  880. scheduledFn.millis,
  881. scheduledFn.params,
  882. true,
  883. scheduledFn.timeoutKey,
  884. scheduledFn.runAtMillis + scheduledFn.millis);
  885. }
  886. function runScheduledFunctions(endTime) {
  887. if (scheduledLookup.length === 0 || scheduledLookup[0] > endTime) {
  888. return;
  889. }
  890. do {
  891. currentTime = scheduledLookup.shift();
  892. var funcsToRun = scheduledFunctions[currentTime];
  893. delete scheduledFunctions[currentTime];
  894. for (var i = 0; i < funcsToRun.length; ++i) {
  895. var funcToRun = funcsToRun[i];
  896. funcToRun.funcToCall.apply(null, funcToRun.params || []);
  897. if (funcToRun.recurring) {
  898. reschedule(funcToRun);
  899. }
  900. }
  901. } while (scheduledLookup.length > 0 &&
  902. // checking first if we're out of time prevents setTimeout(0)
  903. // scheduled in a funcToRun from forcing an extra iteration
  904. currentTime !== endTime &&
  905. scheduledLookup[0] <= endTime);
  906. }
  907. }
  908. return DelayedFunctionScheduler;
  909. };
  910. getJasmineRequireObj().ExceptionFormatter = function() {
  911. function ExceptionFormatter() {
  912. this.message = function(error) {
  913. var message = '';
  914. if (error.name && error.message) {
  915. message += error.name + ': ' + error.message;
  916. } else {
  917. message += error.toString() + ' thrown';
  918. }
  919. if (error.fileName || error.sourceURL) {
  920. message += ' in ' + (error.fileName || error.sourceURL);
  921. }
  922. if (error.line || error.lineNumber) {
  923. message += ' (line ' + (error.line || error.lineNumber) + ')';
  924. }
  925. return message;
  926. };
  927. this.stack = function(error) {
  928. return error ? error.stack : null;
  929. };
  930. }
  931. return ExceptionFormatter;
  932. };
  933. getJasmineRequireObj().Expectation = function() {
  934. var matchers = {};
  935. function Expectation(options) {
  936. this.util = options.util || { buildFailureMessage: function() {} };
  937. this.customEqualityTesters = options.customEqualityTesters || [];
  938. this.actual = options.actual;
  939. this.addExpectationResult = options.addExpectationResult || function(){};
  940. this.isNot = options.isNot;
  941. for (var matcherName in matchers) {
  942. this[matcherName] = matchers[matcherName];
  943. }
  944. }
  945. Expectation.prototype.wrapCompare = function(name, matcherFactory) {
  946. return function() {
  947. var args = Array.prototype.slice.call(arguments, 0),
  948. expected = args.slice(0),
  949. message = '';
  950. args.unshift(this.actual);
  951. var matcher = matcherFactory(this.util, this.customEqualityTesters),
  952. matcherCompare = matcher.compare;
  953. function defaultNegativeCompare() {
  954. var result = matcher.compare.apply(null, args);
  955. result.pass = !result.pass;
  956. return result;
  957. }
  958. if (this.isNot) {
  959. matcherCompare = matcher.negativeCompare || defaultNegativeCompare;
  960. }
  961. var result = matcherCompare.apply(null, args);
  962. if (!result.pass) {
  963. if (!result.message) {
  964. args.unshift(this.isNot);
  965. args.unshift(name);
  966. message = this.util.buildFailureMessage.apply(null, args);
  967. } else {
  968. if (Object.prototype.toString.apply(result.message) === '[object Function]') {
  969. message = result.message();
  970. } else {
  971. message = result.message;
  972. }
  973. }
  974. }
  975. if (expected.length == 1) {
  976. expected = expected[0];
  977. }
  978. // TODO: how many of these params are needed?
  979. this.addExpectationResult(
  980. result.pass,
  981. {
  982. matcherName: name,
  983. passed: result.pass,
  984. message: message,
  985. actual: this.actual,
  986. expected: expected // TODO: this may need to be arrayified/sliced
  987. }
  988. );
  989. };
  990. };
  991. Expectation.addCoreMatchers = function(matchers) {
  992. var prototype = Expectation.prototype;
  993. for (var matcherName in matchers) {
  994. var matcher = matchers[matcherName];
  995. prototype[matcherName] = prototype.wrapCompare(matcherName, matcher);
  996. }
  997. };
  998. Expectation.addMatchers = function(matchersToAdd) {
  999. for (var name in matchersToAdd) {
  1000. var matcher = matchersToAdd[name];
  1001. matchers[name] = Expectation.prototype.wrapCompare(name, matcher);
  1002. }
  1003. };
  1004. Expectation.resetMatchers = function() {
  1005. for (var name in matchers) {
  1006. delete matchers[name];
  1007. }
  1008. };
  1009. Expectation.Factory = function(options) {
  1010. options = options || {};
  1011. var expect = new Expectation(options);
  1012. // TODO: this would be nice as its own Object - NegativeExpectation
  1013. // TODO: copy instead of mutate options
  1014. options.isNot = true;
  1015. expect.not = new Expectation(options);
  1016. return expect;
  1017. };
  1018. return Expectation;
  1019. };
  1020. //TODO: expectation result may make more sense as a presentation of an expectation.
  1021. getJasmineRequireObj().buildExpectationResult = function() {
  1022. function buildExpectationResult(options) {
  1023. var messageFormatter = options.messageFormatter || function() {},
  1024. stackFormatter = options.stackFormatter || function() {};
  1025. return {
  1026. matcherName: options.matcherName,
  1027. expected: options.expected,
  1028. actual: options.actual,
  1029. message: message(),
  1030. stack: stack(),
  1031. passed: options.passed
  1032. };
  1033. function message() {
  1034. if (options.passed) {
  1035. return 'Passed.';
  1036. } else if (options.message) {
  1037. return options.message;
  1038. } else if (options.error) {
  1039. return messageFormatter(options.error);
  1040. }
  1041. return '';
  1042. }
  1043. function stack() {
  1044. if (options.passed) {
  1045. return '';
  1046. }
  1047. var error = options.error;
  1048. if (!error) {
  1049. try {
  1050. throw new Error(message());
  1051. } catch (e) {
  1052. error = e;
  1053. }
  1054. }
  1055. return stackFormatter(error);
  1056. }
  1057. }
  1058. return buildExpectationResult;
  1059. };
  1060. getJasmineRequireObj().MockDate = function() {
  1061. function MockDate(global) {
  1062. var self = this;
  1063. var currentTime = 0;
  1064. if (!global || !global.Date) {
  1065. self.install = function() {};
  1066. self.tick = function() {};
  1067. self.uninstall = function() {};
  1068. return self;
  1069. }
  1070. var GlobalDate = global.Date;
  1071. self.install = function(mockDate) {
  1072. if (mockDate instanceof GlobalDate) {
  1073. currentTime = mockDate.getTime();
  1074. } else {
  1075. currentTime = new GlobalDate().getTime();
  1076. }
  1077. global.Date = FakeDate;
  1078. };
  1079. self.tick = function(millis) {
  1080. millis = millis || 0;
  1081. currentTime = currentTime + millis;
  1082. };
  1083. self.uninstall = function() {
  1084. currentTime = 0;
  1085. global.Date = GlobalDate;
  1086. };
  1087. createDateProperties();
  1088. return self;
  1089. function FakeDate() {
  1090. switch(arguments.length) {
  1091. case 0:
  1092. return new GlobalDate(currentTime);
  1093. case 1:
  1094. return new GlobalDate(arguments[0]);
  1095. case 2:
  1096. return new GlobalDate(arguments[0], arguments[1]);
  1097. case 3:
  1098. return new GlobalDate(arguments[0], arguments[1], arguments[2]);
  1099. case 4:
  1100. return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3]);
  1101. case 5:
  1102. return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
  1103. arguments[4]);
  1104. case 6:
  1105. return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
  1106. arguments[4], arguments[5]);
  1107. case 7:
  1108. return new GlobalDate(arguments[0], arguments[1], arguments[2], arguments[3],
  1109. arguments[4], arguments[5], arguments[6]);
  1110. }
  1111. }
  1112. function createDateProperties() {
  1113. FakeDate.now = function() {
  1114. if (GlobalDate.now) {
  1115. return currentTime;
  1116. } else {
  1117. throw new Error('Browser does not support Date.now()');
  1118. }
  1119. };
  1120. FakeDate.toSource = GlobalDate.toSource;
  1121. FakeDate.toString = GlobalDate.toString;
  1122. FakeDate.parse = GlobalDate.parse;
  1123. FakeDate.UTC = GlobalDate.UTC;
  1124. }
  1125. }
  1126. return MockDate;
  1127. };
  1128. getJasmineRequireObj().ObjectContaining = function(j$) {
  1129. function ObjectContaining(sample) {
  1130. this.sample = sample;
  1131. }
  1132. ObjectContaining.prototype.jasmineMatches = function(other, mismatchKeys, mismatchValues) {
  1133. if (typeof(this.sample) !== 'object') { throw new Error('You must provide an object to objectContaining, not \''+this.sample+'\'.'); }
  1134. mismatchKeys = mismatchKeys || [];
  1135. mismatchValues = mismatchValues || [];
  1136. var hasKey = function(obj, keyName) {
  1137. return obj !== null && !j$.util.isUndefined(obj[keyName]);
  1138. };
  1139. for (var property in this.sample) {
  1140. if (!hasKey(other, property) && hasKey(this.sample, property)) {
  1141. mismatchKeys.push('expected has key \'' + property + '\', but missing from actual.');
  1142. }
  1143. else if (!j$.matchersUtil.equals(other[property], this.sample[property])) {
  1144. mismatchValues.push('\'' + property + '\' was \'' + (other[property] ? j$.util.htmlEscape(other[property].toString()) : other[property]) + '\' in actual, but was \'' + (this.sample[property] ? j$.util.htmlEscape(this.sample[property].toString()) : this.sample[property]) + '\' in expected.');
  1145. }
  1146. }
  1147. return (mismatchKeys.length === 0 && mismatchValues.length === 0);
  1148. };
  1149. ObjectContaining.prototype.jasmineToString = function() {
  1150. return '<jasmine.objectContaining(' + j$.pp(this.sample) + ')>';
  1151. };
  1152. return ObjectContaining;
  1153. };
  1154. getJasmineRequireObj().pp = function(j$) {
  1155. function PrettyPrinter() {
  1156. this.ppNestLevel_ = 0;
  1157. this.seen = [];
  1158. }
  1159. PrettyPrinter.prototype.format = function(value) {
  1160. this.ppNestLevel_++;
  1161. try {
  1162. if (j$.util.isUndefined(value)) {
  1163. this.emitScalar('undefined');
  1164. } else if (value === null) {
  1165. this.emitScalar('null');
  1166. } else if (value === 0 && 1/value === -Infinity) {
  1167. this.emitScalar('-0');
  1168. } else if (value === j$.getGlobal()) {
  1169. this.emitScalar('<global>');
  1170. } else if (value.jasmineToString) {
  1171. this.emitScalar(value.jasmineToString());
  1172. } else if (typeof value === 'string') {
  1173. this.emitString(value);
  1174. } else if (j$.isSpy(value)) {
  1175. this.emitScalar('spy on ' + value.and.identity());
  1176. } else if (value instanceof RegExp) {
  1177. this.emitScalar(value.toString());
  1178. } else if (typeof value === 'function') {
  1179. this.emitScalar('Function');
  1180. } else if (typeof value.nodeType === 'number') {
  1181. this.emitScalar('HTMLNode');
  1182. } else if (value instanceof Date) {
  1183. this.emitScalar('Date(' + value + ')');
  1184. } else if (j$.util.arrayContains(this.seen, value)) {
  1185. this.emitScalar('<circular reference: ' + (j$.isArray_(value) ? 'Array' : 'Object') + '>');
  1186. } else if (j$.isArray_(value) || j$.isA_('Object', value)) {
  1187. this.seen.push(value);
  1188. if (j$.isArray_(value)) {
  1189. this.emitArray(value);
  1190. } else {
  1191. this.emitObject(value);
  1192. }
  1193. this.seen.pop();
  1194. } else {
  1195. this.emitScalar(value.toString());
  1196. }
  1197. } finally {
  1198. this.ppNestLevel_--;
  1199. }
  1200. };
  1201. PrettyPrinter.prototype.iterateObject = function(obj, fn) {
  1202. for (var property in obj) {
  1203. if (!Object.prototype.hasOwnProperty.call(obj, property)) { continue; }
  1204. fn(property, obj.__lookupGetter__ ? (!j$.util.isUndefined(obj.__lookupGetter__(property)) &&
  1205. obj.__lookupGetter__(property) !== null) : false);
  1206. }
  1207. };
  1208. PrettyPrinter.prototype.emitArray = j$.unimplementedMethod_;
  1209. PrettyPrinter.prototype.emitObject = j$.unimplementedMethod_;
  1210. PrettyPrinter.prototype.emitScalar = j$.unimplementedMethod_;
  1211. PrettyPrinter.prototype.emitString = j$.unimplementedMethod_;
  1212. function StringPrettyPrinter() {
  1213. PrettyPrinter.call(this);
  1214. this.string = '';
  1215. }
  1216. j$.util.inherit(StringPrettyPrinter, PrettyPrinter);
  1217. StringPrettyPrinter.prototype.emitScalar = function(value) {
  1218. this.append(value);
  1219. };
  1220. StringPrettyPrinter.prototype.emitString = function(value) {
  1221. this.append('\'' + value + '\'');
  1222. };
  1223. StringPrettyPrinter.prototype.emitArray = function(array) {
  1224. if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
  1225. this.append('Array');
  1226. return;
  1227. }
  1228. var length = Math.min(array.length, j$.MAX_PRETTY_PRINT_ARRAY_LENGTH);
  1229. this.append('[ ');
  1230. for (var i = 0; i < length; i++) {
  1231. if (i > 0) {
  1232. this.append(', ');
  1233. }
  1234. this.format(array[i]);
  1235. }
  1236. if(array.length > length){
  1237. this.append(', ...');
  1238. }
  1239. this.append(' ]');
  1240. };
  1241. StringPrettyPrinter.prototype.emitObject = function(obj) {
  1242. if (this.ppNestLevel_ > j$.MAX_PRETTY_PRINT_DEPTH) {
  1243. this.append('Object');
  1244. return;
  1245. }
  1246. var self = this;
  1247. this.append('{ ');
  1248. var first = true;
  1249. this.iterateObject(obj, function(property, isGetter) {
  1250. if (first) {
  1251. first = false;
  1252. } else {
  1253. self.append(', ');
  1254. }
  1255. self.append(property);
  1256. self.append(': ');
  1257. if (isGetter) {
  1258. self.append('<getter>');
  1259. } else {
  1260. self.format(obj[property]);
  1261. }
  1262. });
  1263. this.append(' }');
  1264. };
  1265. StringPrettyPrinter.prototype.append = function(value) {
  1266. this.string += value;
  1267. };
  1268. return function(value) {
  1269. var stringPrettyPrinter = new StringPrettyPrinter();
  1270. stringPrettyPrinter.format(value);
  1271. return stringPrettyPrinter.string;
  1272. };
  1273. };
  1274. getJasmineRequireObj().QueueRunner = function(j$) {
  1275. function once(fn) {
  1276. var called = false;
  1277. return function() {
  1278. if (!called) {
  1279. called = true;
  1280. fn();
  1281. }
  1282. };
  1283. }
  1284. function QueueRunner(attrs) {
  1285. this.fns = attrs.fns || [];
  1286. this.onComplete = attrs.onComplete || function() {};
  1287. this.clearStack = attrs.clearStack || function(fn) {fn();};
  1288. this.onException = attrs.onException || function() {};
  1289. this.catchException = attrs.catchException || function() { return true; };
  1290. this.enforceTimeout = attrs.enforceTimeout || function() { return false; };
  1291. this.userContext = {};
  1292. this.timer = attrs.timeout || {setTimeout: setTimeout, clearTimeout: clearTimeout};
  1293. }
  1294. QueueRunner.prototype.execute = function() {
  1295. this.run(this.fns, 0);
  1296. };
  1297. QueueRunner.prototype.run = function(fns, recursiveIndex) {
  1298. var length = fns.length,
  1299. self = this,
  1300. iterativeIndex;
  1301. for(iterativeIndex = recursiveIndex; iterativeIndex < length; iterativeIndex++) {
  1302. var fn = fns[iterativeIndex];
  1303. if (fn.length > 0) {
  1304. return attemptAsync(fn);
  1305. } else {
  1306. attemptSync(fn);
  1307. }
  1308. }
  1309. var runnerDone = iterativeIndex >= length;
  1310. if (runnerDone) {
  1311. this.clearStack(this.onComplete);
  1312. }
  1313. function attemptSync(fn) {
  1314. try {
  1315. fn.call(self.userContext);
  1316. } catch (e) {
  1317. handleException(e);
  1318. }
  1319. }
  1320. function attemptAsync(fn) {
  1321. var clearTimeout = function () {
  1322. Function.prototype.apply.apply(self.timer.clearTimeout, [j$.getGlobal(), [timeoutId]]);
  1323. },
  1324. next = once(function () {
  1325. clearTimeout(timeoutId);
  1326. self.run(fns, iterativeIndex + 1);
  1327. }),
  1328. timeoutId;
  1329. if (self.enforceTimeout()) {
  1330. timeoutId = Function.prototype.apply.apply(self.timer.setTimeout, [j$.getGlobal(), [function() {
  1331. self.onException(new Error('Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL.'));
  1332. next();
  1333. }, j$.DEFAULT_TIMEOUT_INTERVAL]]);
  1334. }
  1335. try {
  1336. fn.call(self.userContext, next);
  1337. } catch (e) {
  1338. handleException(e);
  1339. next();
  1340. }
  1341. }
  1342. function handleException(e) {
  1343. self.onException(e);
  1344. if (!self.catchException(e)) {
  1345. //TODO: set a var when we catch an exception and
  1346. //use a finally block to close the loop in a nice way..
  1347. throw e;
  1348. }
  1349. }
  1350. };
  1351. return QueueRunner;
  1352. };
  1353. getJasmineRequireObj().ReportDispatcher = function() {
  1354. function ReportDispatcher(methods) {
  1355. var dispatchedMethods = methods || [];
  1356. for (var i = 0; i < dispatchedMethods.length; i++) {
  1357. var method = dispatchedMethods[i];
  1358. this[method] = (function(m) {
  1359. return function() {
  1360. dispatch(m, arguments);
  1361. };
  1362. }(method));
  1363. }
  1364. var reporters = [];
  1365. this.addReporter = function(reporter) {
  1366. reporters.push(reporter);
  1367. };
  1368. return this;
  1369. function dispatch(method, args) {
  1370. for (var i = 0; i < reporters.length; i++) {
  1371. var reporter = reporters[i];
  1372. if (reporter[method]) {
  1373. reporter[method].apply(reporter, args);
  1374. }
  1375. }
  1376. }
  1377. }
  1378. return ReportDispatcher;
  1379. };
  1380. getJasmineRequireObj().SpyStrategy = function() {
  1381. function SpyStrategy(options) {
  1382. options = options || {};
  1383. var identity = options.name || 'unknown',
  1384. originalFn = options.fn || function() {},
  1385. getSpy = options.getSpy || function() {},
  1386. plan = function() {};
  1387. this.identity = function() {
  1388. return identity;
  1389. };
  1390. this.exec = function() {
  1391. return plan.apply(this, arguments);
  1392. };
  1393. this.callThrough = function() {
  1394. plan = originalFn;
  1395. return getSpy();
  1396. };
  1397. this.returnValue = function(value) {
  1398. plan = function() {
  1399. return value;
  1400. };
  1401. return getSpy();
  1402. };
  1403. this.throwError = function(something) {
  1404. var error = (something instanceof Error) ? something : new Error(something);
  1405. plan = function() {
  1406. throw error;
  1407. };
  1408. return getSpy();
  1409. };
  1410. this.callFake = function(fn) {
  1411. plan = fn;
  1412. return getSpy();
  1413. };
  1414. this.stub = function(fn) {
  1415. plan = function() {};
  1416. return getSpy();
  1417. };
  1418. }
  1419. return SpyStrategy;
  1420. };
  1421. getJasmineRequireObj().Suite = function() {
  1422. function Suite(attrs) {
  1423. this.env = attrs.env;
  1424. this.id = attrs.id;
  1425. this.parentSuite = attrs.parentSuite;
  1426. this.description = attrs.description;
  1427. this.onStart = attrs.onStart || function() {};
  1428. this.resultCallback = attrs.resultCallback || function() {};
  1429. this.clearStack = attrs.clearStack || function(fn) {fn();};
  1430. this.beforeFns = [];
  1431. this.afterFns = [];
  1432. this.queueRunner = attrs.queueRunner || function() {};
  1433. this.disabled = false;
  1434. this.children = [];
  1435. this.result = {
  1436. id: this.id,
  1437. status: this.disabled ? 'disabled' : '',
  1438. description: this.description,
  1439. fullName: this.getFullName()
  1440. };
  1441. }
  1442. Suite.prototype.getFullName = function() {
  1443. var fullName = this.description;
  1444. for (var parentSuite = this.parentSuite; parentSuite; parentSuite = parentSuite.parentSuite) {
  1445. if (parentSuite.parentSuite) {
  1446. fullName = parentSuite.description + ' ' + fullName;
  1447. }
  1448. }
  1449. return fullName;
  1450. };
  1451. Suite.prototype.disable = function() {
  1452. this.disabled = true;
  1453. this.result.status = 'disabled';
  1454. };
  1455. Suite.prototype.beforeEach = function(fn) {
  1456. this.beforeFns.unshift(fn);
  1457. };
  1458. Suite.prototype.afterEach = function(fn) {
  1459. this.afterFns.unshift(fn);
  1460. };
  1461. Suite.prototype.addChild = function(child) {
  1462. this.children.push(child);
  1463. };
  1464. Suite.prototype.execute = function(onComplete) {
  1465. var self = this;
  1466. this.onStart(this);
  1467. if (this.disabled) {
  1468. complete();
  1469. return;
  1470. }
  1471. var allFns = [];
  1472. for (var i = 0; i < this.children.length; i++) {
  1473. allFns.push(wrapChildAsAsync(this.children[i]));
  1474. }
  1475. this.queueRunner({
  1476. fns: allFns,
  1477. onComplete: complete
  1478. });
  1479. function complete() {
  1480. self.resultCallback(self.result);
  1481. if (onComplete) {
  1482. onComplete();
  1483. }
  1484. }
  1485. function wrapChildAsAsync(child) {
  1486. return function(done) { child.execute(done); };
  1487. }
  1488. };
  1489. return Suite;
  1490. };
  1491. if (typeof window == void 0 && typeof exports == 'object') {
  1492. exports.Suite = jasmineRequire.Suite;
  1493. }
  1494. getJasmineRequireObj().Timer = function() {
  1495. var defaultNow = (function(Date) {
  1496. return function() { return new Date().getTime(); };
  1497. })(Date);
  1498. function Timer(options) {
  1499. options = options || {};
  1500. var now = options.now || defaultNow,
  1501. startTime;
  1502. this.start = function() {
  1503. startTime = now();
  1504. };
  1505. this.elapsed = function() {
  1506. return now() - startTime;
  1507. };
  1508. }
  1509. return Timer;
  1510. };
  1511. getJasmineRequireObj().matchersUtil = function(j$) {
  1512. // TODO: what to do about jasmine.pp not being inject? move to JSON.stringify? gut PrettyPrinter?
  1513. return {
  1514. equals: function(a, b, customTesters) {
  1515. customTesters = customTesters || [];
  1516. return eq(a, b, [], [], customTesters);
  1517. },
  1518. contains: function(haystack, needle, customTesters) {
  1519. customTesters = customTesters || [];
  1520. if (Object.prototype.toString.apply(haystack) === '[object Array]') {
  1521. for (var i = 0; i < haystack.length; i++) {
  1522. if (eq(haystack[i], needle, [], [], customTesters)) {
  1523. return true;
  1524. }
  1525. }
  1526. return false;
  1527. }
  1528. return !!haystack && haystack.indexOf(needle) >= 0;
  1529. },
  1530. buildFailureMessage: function() {
  1531. var args = Array.prototype.slice.call(arguments, 0),
  1532. matcherName = args[0],
  1533. isNot = args[1],
  1534. actual = args[2],
  1535. expected = args.slice(3),
  1536. englishyPredicate = matcherName.replace(/[A-Z]/g, function(s) { return ' ' + s.toLowerCase(); });
  1537. var message = 'Expected ' +
  1538. j$.pp(actual) +
  1539. (isNot ? ' not ' : ' ') +
  1540. englishyPredicate;
  1541. if (expected.length > 0) {
  1542. for (var i = 0; i < expected.length; i++) {
  1543. if (i > 0) {
  1544. message += ',';
  1545. }
  1546. message += ' ' + j$.pp(expected[i]);
  1547. }
  1548. }
  1549. return message + '.';
  1550. }
  1551. };
  1552. // Equality function lovingly adapted from isEqual in
  1553. // [Underscore](http://underscorejs.org)
  1554. function eq(a, b, aStack, bStack, customTesters) {
  1555. var result = true;
  1556. for (var i = 0; i < customTesters.length; i++) {
  1557. var customTesterResult = customTesters[i](a, b);
  1558. if (!j$.util.isUndefined(customTesterResult)) {
  1559. return customTesterResult;
  1560. }
  1561. }
  1562. if (a instanceof j$.Any) {
  1563. result = a.jasmineMatches(b);
  1564. if (result) {
  1565. return true;
  1566. }
  1567. }
  1568. if (b instanceof j$.Any) {
  1569. result = b.jasmineMatches(a);
  1570. if (result) {
  1571. return true;
  1572. }
  1573. }
  1574. if (b instanceof j$.ObjectContaining) {
  1575. result = b.jasmineMatches(a);
  1576. if (result) {
  1577. return true;
  1578. }
  1579. }
  1580. if (a instanceof Error && b instanceof Error) {
  1581. return a.message == b.message;
  1582. }
  1583. // Identical objects are equal. `0 === -0`, but they aren't identical.
  1584. // See the [Harmony `egal` proposal](http://wiki.ecmascript.org/doku.php?id=harmony:egal).
  1585. if (a === b) { return a !== 0 || 1 / a == 1 / b; }
  1586. // A strict comparison is necessary because `null == undefined`.
  1587. if (a === null || b === null) { return a === b; }
  1588. var className = Object.prototype.toString.call(a);
  1589. if (className != Object.prototype.toString.call(b)) { return false; }
  1590. switch (className) {
  1591. // Strings, numbers, dates, and booleans are compared by value.
  1592. case '[object String]':
  1593. // Primitives and their corresponding object wrappers are equivalent; thus, `"5"` is
  1594. // equivalent to `new String("5")`.
  1595. return a == String(b);
  1596. case '[object Number]':
  1597. // `NaN`s are equivalent, but non-reflexive. An `egal` comparison is performed for
  1598. // other numeric values.
  1599. return a != +a ? b != +b : (a === 0 ? 1 / a == 1 / b : a == +b);
  1600. case '[object Date]':
  1601. case '[object Boolean]':
  1602. // Coerce dates and booleans to numeric primitive values. Dates are compared by their
  1603. // millisecond representations. Note that invalid dates with millisecond representations
  1604. // of `NaN` are not equivalent.
  1605. return +a == +b;
  1606. // RegExps are compared by their source patterns and flags.
  1607. case '[object RegExp]':
  1608. return a.source == b.source &&
  1609. a.global == b.global &&
  1610. a.multiline == b.multiline &&
  1611. a.ignoreCase == b.ignoreCase;
  1612. }
  1613. if (typeof a != 'object' || typeof b != 'object') { return false; }
  1614. // Assume equality for cyclic structures. The algorithm for detecting cyclic
  1615. // structures is adapted from ES 5.1 section 15.12.3, abstract operation `JO`.
  1616. var length = aStack.length;
  1617. while (length--) {
  1618. // Linear search. Performance is inversely proportional to the number of
  1619. // unique nested structures.
  1620. if (aStack[length] == a) { return bStack[length] == b; }
  1621. }
  1622. // Add the first object to the stack of traversed objects.
  1623. aStack.push(a);
  1624. bStack.push(b);
  1625. var size = 0;
  1626. // Recursively compare objects and arrays.
  1627. if (className == '[object Array]') {
  1628. // Compare array lengths to determine if a deep comparison is necessary.
  1629. size = a.length;
  1630. result = size == b.length;
  1631. if (result) {
  1632. // Deep compare the contents, ignoring non-numeric properties.
  1633. while (size--) {
  1634. if (!(result = eq(a[size], b[size], aStack, bStack, customTesters))) { break; }
  1635. }
  1636. }
  1637. } else {
  1638. // Objects with different constructors are not equivalent, but `Object`s
  1639. // from different frames are.
  1640. var aCtor = a.constructor, bCtor = b.constructor;
  1641. if (aCtor !== bCtor && !(isFunction(aCtor) && (aCtor instanceof aCtor) &&
  1642. isFunction(bCtor) && (bCtor instanceof bCtor))) {
  1643. return false;
  1644. }
  1645. // Deep compare objects.
  1646. for (var key in a) {
  1647. if (has(a, key)) {
  1648. // Count the expected number of properties.
  1649. size++;
  1650. // Deep compare each member.
  1651. if (!(result = has(b, key) && eq(a[key], b[key], aStack, bStack, customTesters))) { break; }
  1652. }
  1653. }
  1654. // Ensure that both objects contain the same number of properties.
  1655. if (result) {
  1656. for (key in b) {
  1657. if (has(b, key) && !(size--)) { break; }
  1658. }
  1659. result = !size;
  1660. }
  1661. }
  1662. // Remove the first object from the stack of traversed objects.
  1663. aStack.pop();
  1664. bStack.pop();
  1665. return result;
  1666. function has(obj, key) {
  1667. return obj.hasOwnProperty(key);
  1668. }
  1669. function isFunction(obj) {
  1670. return typeof obj === 'function';
  1671. }
  1672. }
  1673. };
  1674. getJasmineRequireObj().toBe = function() {
  1675. function toBe() {
  1676. return {
  1677. compare: function(actual, expected) {
  1678. return {
  1679. pass: actual === expected
  1680. };
  1681. }
  1682. };
  1683. }
  1684. return toBe;
  1685. };
  1686. getJasmineRequireObj().toBeCloseTo = function() {
  1687. function toBeCloseTo() {
  1688. return {
  1689. compare: function(actual, expected, precision) {
  1690. if (precision !== 0) {
  1691. precision = precision || 2;
  1692. }
  1693. return {
  1694. pass: Math.abs(expected - actual) < (Math.pow(10, -precision) / 2)
  1695. };
  1696. }
  1697. };
  1698. }
  1699. return toBeCloseTo;
  1700. };
  1701. getJasmineRequireObj().toBeDefined = function() {
  1702. function toBeDefined() {
  1703. return {
  1704. compare: function(actual) {
  1705. return {
  1706. pass: (void 0 !== actual)
  1707. };
  1708. }
  1709. };
  1710. }
  1711. return toBeDefined;
  1712. };
  1713. getJasmineRequireObj().toBeFalsy = function() {
  1714. function toBeFalsy() {
  1715. return {
  1716. compare: function(actual) {
  1717. return {
  1718. pass: !!!actual
  1719. };
  1720. }
  1721. };
  1722. }
  1723. return toBeFalsy;
  1724. };
  1725. getJasmineRequireObj().toBeGreaterThan = function() {
  1726. function toBeGreaterThan() {
  1727. return {
  1728. compare: function(actual, expected) {
  1729. return {
  1730. pass: actual > expected
  1731. };
  1732. }
  1733. };
  1734. }
  1735. return toBeGreaterThan;
  1736. };
  1737. getJasmineRequireObj().toBeLessThan = function() {
  1738. function toBeLessThan() {
  1739. return {
  1740. compare: function(actual, expected) {
  1741. return {
  1742. pass: actual < expected
  1743. };
  1744. }
  1745. };
  1746. }
  1747. return toBeLessThan;
  1748. };
  1749. getJasmineRequireObj().toBeNaN = function(j$) {
  1750. function toBeNaN() {
  1751. return {
  1752. compare: function(actual) {
  1753. var result = {
  1754. pass: (actual !== actual)
  1755. };
  1756. if (result.pass) {
  1757. result.message = 'Expected actual not to be NaN.';
  1758. } else {
  1759. result.message = function() { return 'Expected ' + j$.pp(actual) + ' to be NaN.'; };
  1760. }
  1761. return result;
  1762. }
  1763. };
  1764. }
  1765. return toBeNaN;
  1766. };
  1767. getJasmineRequireObj().toBeNull = function() {
  1768. function toBeNull() {
  1769. return {
  1770. compare: function(actual) {
  1771. return {
  1772. pass: actual === null
  1773. };
  1774. }
  1775. };
  1776. }
  1777. return toBeNull;
  1778. };
  1779. getJasmineRequireObj().toBeTruthy = function() {
  1780. function toBeTruthy() {
  1781. return {
  1782. compare: function(actual) {
  1783. return {
  1784. pass: !!actual
  1785. };
  1786. }
  1787. };
  1788. }
  1789. return toBeTruthy;
  1790. };
  1791. getJasmineRequireObj().toBeUndefined = function() {
  1792. function toBeUndefined() {
  1793. return {
  1794. compare: function(actual) {
  1795. return {
  1796. pass: void 0 === actual
  1797. };
  1798. }
  1799. };
  1800. }
  1801. return toBeUndefined;
  1802. };
  1803. getJasmineRequireObj().toContain = function() {
  1804. function toContain(util, customEqualityTesters) {
  1805. customEqualityTesters = customEqualityTesters || [];
  1806. return {
  1807. compare: function(actual, expected) {
  1808. return {
  1809. pass: util.contains(actual, expected, customEqualityTesters)
  1810. };
  1811. }
  1812. };
  1813. }
  1814. return toContain;
  1815. };
  1816. getJasmineRequireObj().toEqual = function() {
  1817. function toEqual(util, customEqualityTesters) {
  1818. customEqualityTesters = customEqualityTesters || [];
  1819. return {
  1820. compare: function(actual, expected) {
  1821. var result = {
  1822. pass: false
  1823. };
  1824. result.pass = util.equals(actual, expected, customEqualityTesters);
  1825. return result;
  1826. }
  1827. };
  1828. }
  1829. return toEqual;
  1830. };
  1831. getJasmineRequireObj().toHaveBeenCalled = function(j$) {
  1832. function toHaveBeenCalled() {
  1833. return {
  1834. compare: function(actual) {
  1835. var result = {};
  1836. if (!j$.isSpy(actual)) {
  1837. throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
  1838. }
  1839. if (arguments.length > 1) {
  1840. throw new Error('toHaveBeenCalled does not take arguments, use toHaveBeenCalledWith');
  1841. }
  1842. result.pass = actual.calls.any();
  1843. result.message = result.pass ?
  1844. 'Expected spy ' + actual.and.identity() + ' not to have been called.' :
  1845. 'Expected spy ' + actual.and.identity() + ' to have been called.';
  1846. return result;
  1847. }
  1848. };
  1849. }
  1850. return toHaveBeenCalled;
  1851. };
  1852. getJasmineRequireObj().toHaveBeenCalledWith = function(j$) {
  1853. function toHaveBeenCalledWith(util, customEqualityTesters) {
  1854. return {
  1855. compare: function() {
  1856. var args = Array.prototype.slice.call(arguments, 0),
  1857. actual = args[0],
  1858. expectedArgs = args.slice(1),
  1859. result = { pass: false };
  1860. if (!j$.isSpy(actual)) {
  1861. throw new Error('Expected a spy, but got ' + j$.pp(actual) + '.');
  1862. }
  1863. if (!actual.calls.any()) {
  1864. result.message = function() { return 'Expected spy ' + actual.and.identity() + ' to have been called with ' + j$.pp(expectedArgs) + ' but it was never called.'; };
  1865. return result;
  1866. }
  1867. if (util.contains(actual.calls.allArgs(), expectedArgs, customEqualityTesters)) {
  1868. result.pass = true;
  1869. result.message = function() { return 'Expected spy ' + actual.and.identity() + ' not to have been called with ' + j$.pp(expectedArgs) + ' but it was.'; };
  1870. } else {
  1871. 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, '') + '.'; };
  1872. }
  1873. return result;
  1874. }
  1875. };
  1876. }
  1877. return toHaveBeenCalledWith;
  1878. };
  1879. getJasmineRequireObj().toMatch = function() {
  1880. function toMatch() {
  1881. return {
  1882. compare: function(actual, expected) {
  1883. var regexp = new RegExp(expected);
  1884. return {
  1885. pass: regexp.test(actual)
  1886. };
  1887. }
  1888. };
  1889. }
  1890. return toMatch;
  1891. };
  1892. getJasmineRequireObj().toThrow = function(j$) {
  1893. function toThrow(util) {
  1894. return {
  1895. compare: function(actual, expected) {
  1896. var result = { pass: false },
  1897. threw = false,
  1898. thrown;
  1899. if (typeof actual != 'function') {
  1900. throw new Error('Actual is not a Function');
  1901. }
  1902. try {
  1903. actual();
  1904. } catch (e) {
  1905. threw = true;
  1906. thrown = e;
  1907. }
  1908. if (!threw) {
  1909. result.message = 'Expected function to throw an exception.';
  1910. return result;
  1911. }
  1912. if (arguments.length == 1) {
  1913. result.pass = true;
  1914. result.message = function() { return 'Expected function not to throw, but it threw ' + j$.pp(thrown) + '.'; };
  1915. return result;
  1916. }
  1917. if (util.equals(thrown, expected)) {
  1918. result.pass = true;
  1919. result.message = function() { return 'Expected function not to throw ' + j$.pp(expected) + '.'; };
  1920. } else {
  1921. result.message = function() { return 'Expected function to throw ' + j$.pp(expected) + ', but it threw ' + j$.pp(thrown) + '.'; };
  1922. }
  1923. return result;
  1924. }
  1925. };
  1926. }
  1927. return toThrow;
  1928. };
  1929. getJasmineRequireObj().toThrowError = function(j$) {
  1930. function toThrowError (util) {
  1931. return {
  1932. compare: function(actual) {
  1933. var threw = false,
  1934. pass = {pass: true},
  1935. fail = {pass: false},
  1936. thrown,
  1937. errorType,
  1938. message,
  1939. regexp,
  1940. name,
  1941. constructorName;
  1942. if (typeof actual != 'function') {
  1943. throw new Error('Actual is not a Function');
  1944. }
  1945. extractExpectedParams.apply(null, arguments);
  1946. try {
  1947. actual();
  1948. } catch (e) {
  1949. threw = true;
  1950. thrown = e;
  1951. }
  1952. if (!threw) {
  1953. fail.message = 'Expected function to throw an Error.';
  1954. return fail;
  1955. }
  1956. if (!(thrown instanceof Error)) {
  1957. fail.message = function() { return 'Expected function to throw an Error, but it threw ' + j$.pp(thrown) + '.'; };
  1958. return fail;
  1959. }
  1960. if (arguments.length == 1) {
  1961. pass.message = 'Expected function not to throw an Error, but it threw ' + fnNameFor(thrown) + '.';
  1962. return pass;
  1963. }
  1964. if (errorType) {
  1965. name = fnNameFor(errorType);
  1966. constructorName = fnNameFor(thrown.constructor);
  1967. }
  1968. if (errorType && message) {
  1969. if (thrown.constructor == errorType && util.equals(thrown.message, message)) {
  1970. pass.message = function() { return 'Expected function not to throw ' + name + ' with message ' + j$.pp(message) + '.'; };
  1971. return pass;
  1972. } else {
  1973. fail.message = function() { return 'Expected function to throw ' + name + ' with message ' + j$.pp(message) +
  1974. ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; };
  1975. return fail;
  1976. }
  1977. }
  1978. if (errorType && regexp) {
  1979. if (thrown.constructor == errorType && regexp.test(thrown.message)) {
  1980. pass.message = function() { return 'Expected function not to throw ' + name + ' with message matching ' + j$.pp(regexp) + '.'; };
  1981. return pass;
  1982. } else {
  1983. fail.message = function() { return 'Expected function to throw ' + name + ' with message matching ' + j$.pp(regexp) +
  1984. ', but it threw ' + constructorName + ' with message ' + j$.pp(thrown.message) + '.'; };
  1985. return fail;
  1986. }
  1987. }
  1988. if (errorType) {
  1989. if (thrown.constructor == errorType) {
  1990. pass.message = 'Expected function not to throw ' + name + '.';
  1991. return pass;
  1992. } else {
  1993. fail.message = 'Expected function to throw ' + name + ', but it threw ' + constructorName + '.';
  1994. return fail;
  1995. }
  1996. }
  1997. if (message) {
  1998. if (thrown.message == message) {
  1999. pass.message = function() { return 'Expected function not to throw an exception with message ' + j$.pp(message) + '.'; };
  2000. return pass;
  2001. } else {
  2002. fail.message = function() { return 'Expected function to throw an exception with message ' + j$.pp(message) +
  2003. ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; };
  2004. return fail;
  2005. }
  2006. }
  2007. if (regexp) {
  2008. if (regexp.test(thrown.message)) {
  2009. pass.message = function() { return 'Expected function not to throw an exception with a message matching ' + j$.pp(regexp) + '.'; };
  2010. return pass;
  2011. } else {
  2012. fail.message = function() { return 'Expected function to throw an exception with a message matching ' + j$.pp(regexp) +
  2013. ', but it threw an exception with message ' + j$.pp(thrown.message) + '.'; };
  2014. return fail;
  2015. }
  2016. }
  2017. function fnNameFor(func) {
  2018. return func.name || func.toString().match(/^\s*function\s*(\w*)\s*\(/)[1];
  2019. }
  2020. function extractExpectedParams() {
  2021. if (arguments.length == 1) {
  2022. return;
  2023. }
  2024. if (arguments.length == 2) {
  2025. var expected = arguments[1];
  2026. if (expected instanceof RegExp) {
  2027. regexp = expected;
  2028. } else if (typeof expected == 'string') {
  2029. message = expected;
  2030. } else if (checkForAnErrorType(expected)) {
  2031. errorType = expected;
  2032. }
  2033. if (!(errorType || message || regexp)) {
  2034. throw new Error('Expected is not an Error, string, or RegExp.');
  2035. }
  2036. } else {
  2037. if (checkForAnErrorType(arguments[1])) {
  2038. errorType = arguments[1];
  2039. } else {
  2040. throw new Error('Expected error type is not an Error.');
  2041. }
  2042. if (arguments[2] instanceof RegExp) {
  2043. regexp = arguments[2];
  2044. } else if (typeof arguments[2] == 'string') {
  2045. message = arguments[2];
  2046. } else {
  2047. throw new Error('Expected error message is not a string or RegExp.');
  2048. }
  2049. }
  2050. }
  2051. function checkForAnErrorType(type) {
  2052. if (typeof type !== 'function') {
  2053. return false;
  2054. }
  2055. var Surrogate = function() {};
  2056. Surrogate.prototype = type.prototype;
  2057. return (new Surrogate()) instanceof Error;
  2058. }
  2059. }
  2060. };
  2061. }
  2062. return toThrowError;
  2063. };
  2064. getJasmineRequireObj().interface = function(jasmine, env) {
  2065. var jasmineInterface = {
  2066. describe: function(description, specDefinitions) {
  2067. return env.describe(description, specDefinitions);
  2068. },
  2069. xdescribe: function(description, specDefinitions) {
  2070. return env.xdescribe(description, specDefinitions);
  2071. },
  2072. it: function(desc, func) {
  2073. return env.it(desc, func);
  2074. },
  2075. xit: function(desc, func) {
  2076. return env.xit(desc, func);
  2077. },
  2078. beforeEach: function(beforeEachFunction) {
  2079. return env.beforeEach(beforeEachFunction);
  2080. },
  2081. afterEach: function(afterEachFunction) {
  2082. return env.afterEach(afterEachFunction);
  2083. },
  2084. expect: function(actual) {
  2085. return env.expect(actual);
  2086. },
  2087. pending: function() {
  2088. return env.pending();
  2089. },
  2090. spyOn: function(obj, methodName) {
  2091. return env.spyOn(obj, methodName);
  2092. },
  2093. jsApiReporter: new jasmine.JsApiReporter({
  2094. timer: new jasmine.Timer()
  2095. }),
  2096. jasmine: jasmine
  2097. };
  2098. jasmine.addCustomEqualityTester = function(tester) {
  2099. env.addCustomEqualityTester(tester);
  2100. };
  2101. jasmine.addMatchers = function(matchers) {
  2102. return env.addMatchers(matchers);
  2103. };
  2104. jasmine.clock = function() {
  2105. return env.clock;
  2106. };
  2107. return jasmineInterface;
  2108. };
  2109. getJasmineRequireObj().version = function() {
  2110. return '2.0.2';
  2111. };