├── .gitignore ├── CODEOWNERS ├── 04.DOM_manipulation ├── src │ └── domManipulation.js ├── runner.html └── spec │ └── domManipulation.js ├── 07.learnQuery ├── src │ └── learnQuery.js ├── runner.html └── spec │ └── learnQuery.js ├── 02.CSS_manipulation ├── src │ └── cssProp.js ├── runner.html └── spec │ └── cssProp.js ├── 05.AJAX_Request ├── src │ └── ajaxRequest.js ├── runner.html └── spec │ └── ajaxRequest.js ├── 01.dom_selector ├── src │ └── selector.js ├── runner.html └── spec │ └── selector.js ├── 06.event_listeners ├── src │ └── eventListeners.js ├── runner.html └── spec │ └── eventListeners.js ├── lib ├── jasmine-2.1.3 │ ├── jasmine_favicon.png │ ├── boot.js │ ├── console.js │ ├── jasmine-html.js │ ├── jasmine.css │ └── jasmine.js ├── mock-ajax.js └── jasmine-fixture.js ├── 03.CSS_class_manipulation ├── src │ └── cssClassManipulation.js ├── runner.html └── spec │ └── cssClassManipulation.js ├── 00.example ├── spec │ └── example.js ├── runner.html └── src │ └── example.js ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @darrac @nives113 @thabalija @fvoska @safo6m @DarkoKukovec -------------------------------------------------------------------------------- /04.DOM_manipulation/src/domManipulation.js: -------------------------------------------------------------------------------- 1 | var dom = function(){ 2 | // code goes here 3 | }; -------------------------------------------------------------------------------- /07.learnQuery/src/learnQuery.js: -------------------------------------------------------------------------------- 1 | function learnQuery(elementsSelector) { 2 | //code goes here 3 | } -------------------------------------------------------------------------------- /02.CSS_manipulation/src/cssProp.js: -------------------------------------------------------------------------------- 1 | function cssProp() { 2 | 'use strict'; 3 | 4 | //code goes here 5 | } -------------------------------------------------------------------------------- /05.AJAX_Request/src/ajaxRequest.js: -------------------------------------------------------------------------------- 1 | function ajaxReq() { 2 | 'use strict'; 3 | // code goes here 4 | } -------------------------------------------------------------------------------- /01.dom_selector/src/selector.js: -------------------------------------------------------------------------------- 1 | var domSelector = function(selectors) { 2 | 'use strict'; 3 | 4 | //code goes here 5 | }; -------------------------------------------------------------------------------- /06.event_listeners/src/eventListeners.js: -------------------------------------------------------------------------------- 1 | var eventListener = (function() { 2 | 'use strict'; 3 | //code goes here 4 | })(); -------------------------------------------------------------------------------- /lib/jasmine-2.1.3/jasmine_favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/infinum/learnQuery/HEAD/lib/jasmine-2.1.3/jasmine_favicon.png -------------------------------------------------------------------------------- /03.CSS_class_manipulation/src/cssClassManipulation.js: -------------------------------------------------------------------------------- 1 | var cssClass = (function() { 2 | 'use strict'; 3 | 4 | // code goes here 5 | })(); -------------------------------------------------------------------------------- /00.example/spec/example.js: -------------------------------------------------------------------------------- 1 | describe('Fibonacci calculator', function() { 2 | 'use strict'; 3 | 4 | var fibonacciCalculator; 5 | var song; 6 | 7 | beforeEach(function() { 8 | fibonacciCalculator = new Fibonacci(); 9 | }); 10 | 11 | it('should cover small numbers', function() { 12 | expect(fibonacciCalculator.compute(0)).toBe(1); 13 | expect(fibonacciCalculator.compute(1)).toBe(1); 14 | }); 15 | 16 | it('should cover bigger numbers', function() { 17 | expect(fibonacciCalculator.compute(27)).toBe(317811); 18 | }); 19 | 20 | it('should cover negative numbers', function() { 21 | expect(function() { 22 | fibonacciCalculator.compute(-1); 23 | }).toThrowError('Number must be positive'); 24 | }); 25 | 26 | it('should cover invalid values', function() { 27 | expect(function() { 28 | fibonacciCalculator.compute('the answer to life the universe and everything'); 29 | }).toThrowError('Parameter must be a number'); 30 | }); 31 | }); -------------------------------------------------------------------------------- /00.example/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Fibonacci spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /01.dom_selector/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DOM selector spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /02.CSS_manipulation/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jasmine Spec Runner v2.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /04.DOM_manipulation/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | DOM Manipulation spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /06.event_listeners/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Event listeners spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /03.CSS_class_manipulation/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSS class manipulation spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Infinum 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /05.AJAX_Request/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | AJAX spec runner 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /00.example/src/example.js: -------------------------------------------------------------------------------- 1 | var Fibonacci = function() { 2 | 'use strict'; 3 | 4 | // Predefined fibonacci sequence values 5 | var preComputed = { 6 | 0: 1, 7 | 1: 1 8 | }; 9 | 10 | function step(num) { 11 | // A function can access parents variables (this is called a closure) 12 | if (preComputed[num]) { 13 | return preComputed[num]; 14 | } else { 15 | return step(num - 1) + step(num - 2); 16 | } 17 | } 18 | 19 | function computeFn(num) { 20 | if (isNaN(num)) { // Making sure the parameter is a number 21 | throw new Error('Parameter must be a number'); 22 | } else if (num < 0) { // Fibonacci sequence is not defined for negative numbers 23 | throw new Error('Number must be positive'); 24 | } else { 25 | // Making sure the parameter is an integer. 26 | // There is no need to throw an error here since we can recover from it. 27 | num = Math.round(num); 28 | 29 | return step(num); 30 | } 31 | } 32 | 33 | // Values that are being exposed to the outside are returned. 34 | // This can either be a function, variable or an object that contains multiple functions and variables. 35 | // In this case, we are exporting function 'computeFn' that will be called 'compute' outside. 36 | return { 37 | compute: computeFn 38 | }; 39 | }; -------------------------------------------------------------------------------- /07.learnQuery/runner.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Jasmine Spec Runner v2.0.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /02.CSS_manipulation/spec/cssProp.js: -------------------------------------------------------------------------------- 1 | /*global affix, cssProp*/ 2 | 3 | describe('cssProp', function() { 4 | 'use strict'; 5 | 6 | var $selectedElement, selectedElement; 7 | 8 | beforeEach(function() { 9 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 10 | 11 | $selectedElement = $('#toddler'); 12 | selectedElement = $selectedElement[0]; 13 | }); 14 | 15 | it('should set a CSS attribute of an HTML element', function() { 16 | cssProp(selectedElement, 'width', '9001px'); 17 | expect($selectedElement.css('width')).toBe('9001px'); 18 | }); 19 | 20 | it('should return an existing CSS property value of an HTML element', function() { 21 | $selectedElement.css('display', 'none'); 22 | expect(cssProp(selectedElement, 'display')).toBe('none'); 23 | }); 24 | 25 | it('should set multiple CSS properties of an HTML element', function() { 26 | cssProp(selectedElement, { 27 | 'height': '100px', 28 | 'display': 'none' 29 | }); 30 | 31 | expect($selectedElement.css('display')).toBe('none'); 32 | expect($selectedElement.css('height')).toBe('100px'); 33 | }); 34 | 35 | it('should properly set CSS properties if called multiple times on different HTML elements', function() { 36 | var $anotherEl = $('.learn-query-testing'); 37 | var anotherEl = $anotherEl[0]; 38 | 39 | cssProp(selectedElement, 'height', '100px'); 40 | cssProp(anotherEl, 'display', 'none'); 41 | 42 | expect($selectedElement.css('height')).toBe('100px'); 43 | expect($selectedElement.css('display')).not.toBe('none'); 44 | expect($anotherEl.css('display')).toBe('none'); 45 | }); 46 | }); -------------------------------------------------------------------------------- /03.CSS_class_manipulation/spec/cssClassManipulation.js: -------------------------------------------------------------------------------- 1 | /*global affix, cssClass*/ 2 | 3 | describe('CssClassManipulation', function() { 4 | 'use strict'; 5 | 6 | var $selectedElement, selectedElement; 7 | 8 | beforeEach(function() { 9 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 10 | 11 | $selectedElement = $('#toddler'); 12 | selectedElement = $selectedElement[0]; 13 | }); 14 | 15 | it('should add a css class to the element', function() { 16 | cssClass.add(selectedElement, 'building'); 17 | expect($selectedElement.hasClass('building')).toBe(true); 18 | }); 19 | 20 | it('should not overwrite existing css classes', function() { 21 | $selectedElement.addClass('spooky'); 22 | cssClass.add(selectedElement, 'building'); 23 | 24 | expect($selectedElement.hasClass('building')).toBe(true); 25 | expect($selectedElement.hasClass('spooky')).toBe(true); 26 | }); 27 | 28 | it('should remove a specific css class of the element', function() { 29 | $selectedElement.addClass('very-important-class'); 30 | $selectedElement.addClass('super-cool-class'); 31 | 32 | cssClass.remove(selectedElement, 'super-cool-class'); 33 | 34 | expect($selectedElement.hasClass('super-cool-class')).toBe(false); 35 | expect($selectedElement.hasClass('very-important-class')).toBe(true); 36 | }); 37 | 38 | it('should toggle a css class of the element', function() { 39 | $selectedElement.addClass('hidden-tower'); 40 | 41 | cssClass.toggle(selectedElement, 'hidden-tower'); 42 | expect($selectedElement.hasClass('hidden-tower')).toBe(false); 43 | 44 | cssClass.toggle(selectedElement, 'hidden-tower'); 45 | expect($selectedElement.hasClass('hidden-tower')).toBe(true); 46 | }); 47 | 48 | it('should return true if a HTML element has a given css class', function() { 49 | $selectedElement.addClass('hidden-tower'); 50 | expect(cssClass.has(selectedElement, 'hidden-tower')).toBe(true); 51 | }); 52 | 53 | it('should return false if a HTML element doesn\'t have a given css class', function() { 54 | $selectedElement.removeClass('hidden-tower'); 55 | expect(cssClass.has(selectedElement, 'hidden-tower')).toBe(false); 56 | }); 57 | }); -------------------------------------------------------------------------------- /07.learnQuery/spec/learnQuery.js: -------------------------------------------------------------------------------- 1 | /*global affix, learnQuery*/ 2 | 3 | describe('LearnQuery', function() { 4 | 'use strict'; 5 | 6 | var $selectedElement, selectedElement, methods; 7 | 8 | beforeEach(function() { 9 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 10 | 11 | methods = { 12 | showLove: function() { 13 | console.log('<3 JavaScript <3'); 14 | }, 15 | 16 | giveLove: function() { 17 | console.log('==> JavaScript ==>'); 18 | return '==> JavaScript ==>'; 19 | } 20 | }; 21 | 22 | spyOn(methods, 'showLove'); 23 | spyOn(methods, 'giveLove'); 24 | 25 | $selectedElement = $('#toddler'); 26 | selectedElement = $selectedElement.get(0); 27 | }); 28 | 29 | it('should allow cssClass method chaining', function() { 30 | learnQuery('#toddler').addClass('one').addClass('two').removeClass('one'); 31 | 32 | expect($selectedElement.hasClass('one')).toBe(false); 33 | expect($selectedElement.hasClass('two')).toBe(true); 34 | }); 35 | 36 | it('should allow dom method chaining', function() { 37 | var newElementH4 = document.createElement('h4'); 38 | var newElementH2 = document.createElement('h2'); 39 | var newElementSpan = document.createElement('span'); 40 | 41 | learnQuery('#toddler').before(newElementH4).after(newElementH2).append(newElementSpan); 42 | 43 | expect($selectedElement.next()[0]).toBe(newElementH2); 44 | expect($selectedElement.prev()[0]).toBe(newElementH4); 45 | expect($selectedElement.children().last()[0]).toBe(newElementSpan); 46 | }); 47 | 48 | it('should allow eventListener method chaining', function() { 49 | learnQuery('#toddler').on('click', methods.showLove).on('click', methods.giveLove).trigger('click'); 50 | 51 | expect(methods.showLove.calls.count()).toBe(1); 52 | expect(methods.giveLove.calls.count()).toBe(1); 53 | }); 54 | 55 | it('should allow multiple methods chaining', function() { 56 | var newElementH4 = document.createElement('h4'); 57 | 58 | learnQuery('#toddler').before(newElementH4).addClass('blury').on('hover', methods.showLove).trigger('hover'); 59 | 60 | expect($selectedElement.prev()[0]).toBe(newElementH4); 61 | expect($selectedElement.hasClass('blury')).toBe(true); 62 | expect(methods.showLove).toHaveBeenCalled(); 63 | }); 64 | }); -------------------------------------------------------------------------------- /01.dom_selector/spec/selector.js: -------------------------------------------------------------------------------- 1 | /*global affix, selector*/ 2 | 3 | describe('Selector', function() { 4 | 'use strict'; 5 | 6 | beforeEach(function() { 7 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 8 | }); 9 | 10 | it('should select an empty array if the element does not exist in DOM', function() { 11 | var selector = '.some-element-not-in-the-dom'; 12 | 13 | // We're calling $.makeArray because we need to transform jQuery result set into real array object 14 | var expectedSelectedElement = $.makeArray($(selector)); 15 | var selectedElement = domSelector(selector); 16 | 17 | expect(selectedElement).toEqual(expectedSelectedElement); 18 | expect(selectedElement.length).toBe(0); 19 | }); 20 | 21 | it('should select a DOM element with given ID', function() { 22 | var id = 'toddler'; 23 | var expectedSelectedElement = $.makeArray($('#' + id)); 24 | var selectedElement = domSelector('#' + id); 25 | 26 | expect(selectedElement).toEqual(expectedSelectedElement); 27 | expect(selectedElement.length).toBe(1); 28 | expect(selectedElement[0] instanceof HTMLElement).toBe(true); 29 | expect(selectedElement[0]).toBe(expectedSelectedElement[0]); 30 | expect(selectedElement[0].id).toBe(id); 31 | }); 32 | 33 | it('should select DOM elements with a given class name', function() { 34 | var className = '.infinum'; 35 | var selectedElementsArray = domSelector(className); 36 | var expectedHTMLElementsArray = $.makeArray($(className)); 37 | 38 | expect(selectedElementsArray.length).toBe(expectedHTMLElementsArray.length); 39 | 40 | // We need to check for each element if it's in the expected result set because element order is not guaranteed 41 | selectedElementsArray.forEach(function(element) { 42 | expect(expectedHTMLElementsArray.indexOf(element)).not.toBe(-1); 43 | }); 44 | }); 45 | 46 | it('should select DOM elements with a given tag name', function() { 47 | var tagName = 'input'; 48 | var selectedElementsArray = domSelector(tagName); 49 | var expectedHTMLElementsArray = $.makeArray($(tagName)); 50 | 51 | selectedElementsArray.forEach(function(element) { 52 | expect(expectedHTMLElementsArray.indexOf(element)).not.toBe(-1); 53 | }); 54 | }); 55 | 56 | it('should throw an expection for invalid selector', function() { 57 | expect(function() { 58 | domSelector(')(?/'); 59 | }).toThrowError(); 60 | }); 61 | }); 62 | -------------------------------------------------------------------------------- /04.DOM_manipulation/spec/domManipulation.js: -------------------------------------------------------------------------------- 1 | describe('domManipulation', function() { 2 | 'use strict'; 3 | 4 | var $selectedElement, selectedElement; 5 | 6 | beforeEach(function() { 7 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 8 | 9 | $selectedElement = $('#toddler'); 10 | selectedElement = $selectedElement[0]; 11 | }); 12 | 13 | it('should be able to remove a HTML element', function() { 14 | expect(document.contains(selectedElement)).toBe(true); 15 | dom.remove(selectedElement); 16 | expect(document.contains(selectedElement)).toBe(false); 17 | }); 18 | 19 | it('should append a HTML element to the given element', function() { 20 | var newElement = document.createElement('h4'); 21 | var initialChildrenCount = $selectedElement.children().length; 22 | 23 | expect(initialChildrenCount).toBeGreaterThan(0); 24 | 25 | dom.append(selectedElement, newElement); 26 | 27 | expect($selectedElement.children().length).toBe(initialChildrenCount + 1); 28 | expect($selectedElement.children()[initialChildrenCount]).toBe(newElement); 29 | }); 30 | 31 | it('should prepend a HTML element to the given element', function() { 32 | var newElement = document.createElement('h4'); 33 | var initialChildrenCount = $selectedElement.children().length; 34 | 35 | expect(initialChildrenCount).toBeGreaterThan(0); 36 | 37 | dom.prepend(selectedElement, newElement); 38 | 39 | expect($selectedElement.children().length).toBe(initialChildrenCount + 1); 40 | expect($selectedElement.children()[0]).toBe(newElement); 41 | }); 42 | 43 | it('should be able to add a new HTML element after a given HTML element', function() { 44 | var newElement = document.createElement('div'); 45 | 46 | var $targetElement = $('.creature'); 47 | var targetElement = $targetElement[0]; 48 | 49 | expect($targetElement.next()[0]).not.toBe(newElement); 50 | dom.after(targetElement, newElement); 51 | expect($targetElement.next()[0]).toBe(newElement); 52 | }); 53 | 54 | it('should be able to add a new HTML element before a given HTML element', function() { 55 | var newElement = document.createElement('main'); 56 | 57 | expect($selectedElement.prev()[0]).not.toBe(newElement); 58 | dom.before(selectedElement, newElement); 59 | expect($selectedElement.prev()[0]).toBe(newElement); 60 | }); 61 | 62 | it('should return a value of a given HTML non-select element', function() { 63 | var element = $('.creature')[0]; 64 | var elementValue = dom.val(element); 65 | 66 | expect(elementValue).toBe('unicorn'); 67 | 68 | element.value = 'pikachu'; 69 | 70 | elementValue = dom.val(element); 71 | expect(elementValue).toBe('pikachu'); 72 | }); 73 | 74 | it('should return a value of a given select HTML element', function(){ 75 | $selectedElement = $selectedElement.affix('select option[value="Option1"]+option[value="Option2"][selected=true]'); 76 | expect(dom.val(document.querySelector('select'))).toBe('Option2'); 77 | }); 78 | 79 | it('should not throw exception if the target element is not in the DOM when calling dom.remove', function() { 80 | var elementNotInTheDom = document.createElement('div'); 81 | expect(function() { 82 | dom.remove(elementNotInTheDom); 83 | }).not.toThrowError(); 84 | }); 85 | 86 | it('should not throw exception if the target element is not in the DOM when calling dom.after', function() { 87 | var elementNotInTheDom = document.createElement('div'); 88 | var newElement = document.createElement('h4'); 89 | 90 | expect(function() { 91 | dom.after(elementNotInTheDom, newElement); 92 | }).not.toThrowError(); 93 | }); 94 | }); 95 | -------------------------------------------------------------------------------- /05.AJAX_Request/spec/ajaxRequest.js: -------------------------------------------------------------------------------- 1 | /*global ajaxReq*/ 2 | 3 | describe('AjaxRequest', function() { 4 | 'use strict'; 5 | 6 | beforeEach(function() { 7 | jasmine.Ajax.install(); 8 | 9 | this.onSuccessSpy = jasmine.createSpy('success'); 10 | this.onFailureSpy = jasmine.createSpy('failure'); 11 | this.onCompleteSpy = jasmine.createSpy('complete'); 12 | 13 | jasmine.Ajax.stubRequest('/infinum/index').andReturn({ 14 | status: 200, 15 | responseText: '{ "response": "incredible cool things" }' 16 | }); 17 | 18 | jasmine.Ajax.stubRequest('/infinum/not-found').andReturn({ 19 | "status": 404, 20 | "responseText": 'page not found' 21 | }); 22 | }); 23 | 24 | afterEach(function() { 25 | jasmine.Ajax.uninstall(); 26 | }); 27 | 28 | it('should make a successful ajax request', function() { 29 | ajaxReq('/infinum/index', { 30 | success: this.onSuccessSpy, 31 | complete: this.onCompleteSpy, 32 | failure: this.onFailureSpy 33 | }); 34 | 35 | expect(this.onSuccessSpy).toHaveBeenCalled(); 36 | expect(this.onFailureSpy).not.toHaveBeenCalled(); 37 | expect(this.onCompleteSpy).toHaveBeenCalled(); 38 | }); 39 | 40 | it('should make POST ajax request', function() { 41 | ajaxReq('/infinum/index', { 42 | success: this.onSuccessSpy, 43 | complete: this.onCompleteSpy, 44 | failure: this.onFailureSpy, 45 | method: 'POST' 46 | }); 47 | 48 | expect(jasmine.Ajax.requests.mostRecent().method).toBe('POST'); 49 | expect(this.onSuccessSpy).toHaveBeenCalled(); 50 | expect(this.onFailureSpy).not.toHaveBeenCalled(); 51 | expect(this.onCompleteSpy).toHaveBeenCalled(); 52 | }); 53 | 54 | it('should call a custom function with proper context on failure', function() { 55 | var context = { 56 | secretUnicorn: 'Glumpsy' 57 | }; 58 | 59 | var onFailure = function(xhr, status, responseText) { 60 | expect(status).toBe(404); 61 | expect(responseText).toBe('page not found'); 62 | expect(this).toBe(context); 63 | expect(this.secretUnicorn).toBe('Glumpsy'); 64 | }; 65 | 66 | var methods = { 67 | onFailure: onFailure 68 | }; 69 | 70 | spyOn(methods, 'onFailure').and.callFake(onFailure); 71 | 72 | ajaxReq('/infinum/not-found', { 73 | success: this.onSuccessSpy, 74 | failure: methods.onFailure, 75 | complete: this.onCompleteSpy, 76 | context: context 77 | }); 78 | 79 | expect(methods.onFailure).toHaveBeenCalled(); 80 | expect(this.onCompleteSpy).toHaveBeenCalled(); 81 | expect(this.onSuccessSpy).not.toHaveBeenCalled(); 82 | }); 83 | 84 | it('should call a custom function with proper context on success', function() { 85 | var context = { 86 | secretUnicorn: 'Glumpsy' 87 | }; 88 | 89 | var onSuccess = function(data, status, xhr) { 90 | expect(status).toBe(200); 91 | expect(data.response).toBe('incredible cool things'); 92 | expect(this).toBe(context); 93 | expect(this.secretUnicorn).toBe('Glumpsy'); 94 | }; 95 | 96 | var methods = { 97 | onSuccess: onSuccess 98 | }; 99 | 100 | spyOn(methods, 'onSuccess').and.callFake(onSuccess); 101 | 102 | ajaxReq('/infinum/index', { 103 | success: methods.onSuccess, 104 | failure: this.onFailureSpy, 105 | complete: this.onCompleteSpy, 106 | context: context 107 | }); 108 | 109 | expect(methods.onSuccess).toHaveBeenCalled(); 110 | expect(this.onCompleteSpy).toHaveBeenCalled(); 111 | expect(this.onFailureSpy).not.toHaveBeenCalled(); 112 | }); 113 | 114 | it('should call a custom function with proper context when request is completed', function() { 115 | var context = { 116 | secretUnicorn: 'Glumpsy' 117 | }; 118 | 119 | var onComplete = function(xhr, status) { 120 | expect(status).toBe(200); 121 | expect(this).toBe(context); 122 | expect(this.secretUnicorn).toBe('Glumpsy'); 123 | }; 124 | 125 | var methods = { 126 | onComplete: onComplete 127 | }; 128 | 129 | spyOn(methods, 'onComplete').and.callFake(onComplete); 130 | 131 | ajaxReq('/infinum/index', { 132 | success: this.onSuccessSpy, 133 | failure: this.onFailureSpy, 134 | complete: methods.onComplete, 135 | context: context 136 | }); 137 | 138 | expect(methods.onComplete).toHaveBeenCalled(); 139 | expect(this.onSuccessSpy).toHaveBeenCalled(); 140 | expect(this.onFailureSpy).not.toHaveBeenCalled(); 141 | }); 142 | }); -------------------------------------------------------------------------------- /lib/jasmine-2.1.3/boot.js: -------------------------------------------------------------------------------- 1 | /** 2 | Starting with version 2.0, this file "boots" Jasmine, performing all of the necessary initialization before executing the loaded environment and all of a project's specs. This file should be loaded after `jasmine.js` and `jasmine_html.js`, but before any project source files or spec files are loaded. Thus this file can also be used to customize Jasmine for a project. 3 | 4 | If a project is using Jasmine via the standalone distribution, this file can be customized directly. If a project is using Jasmine via the [Ruby gem][jasmine-gem], this file can be copied into the support directory via `jasmine copy_boot_js`. Other environments (e.g., Python) will have different mechanisms. 5 | 6 | The location of `boot.js` can be specified and/or overridden in `jasmine.yml`. 7 | 8 | [jasmine-gem]: http://github.com/pivotal/jasmine-gem 9 | */ 10 | 11 | (function() { 12 | 13 | /** 14 | * ## Require & Instantiate 15 | * 16 | * Require Jasmine's core files. Specifically, this requires and attaches all of Jasmine's code to the `jasmine` reference. 17 | */ 18 | window.jasmine = jasmineRequire.core(jasmineRequire); 19 | 20 | /** 21 | * Since this is being run in a browser and the results should populate to an HTML page, require the HTML-specific Jasmine code, injecting the same reference. 22 | */ 23 | jasmineRequire.html(jasmine); 24 | 25 | /** 26 | * Create the Jasmine environment. This is used to run all specs in a project. 27 | */ 28 | var env = jasmine.getEnv(); 29 | 30 | /** 31 | * ## The Global Interface 32 | * 33 | * Build up the functions that will be exposed as the Jasmine public interface. A project can customize, rename or alias any of these functions as desired, provided the implementation remains unchanged. 34 | */ 35 | var jasmineInterface = jasmineRequire.interface(jasmine, env); 36 | 37 | /** 38 | * Add all of the Jasmine global/public interface to the proper global, so a project can use the public interface directly. For example, calling `describe` in specs instead of `jasmine.getEnv().describe`. 39 | */ 40 | if (typeof window == "undefined" && typeof exports == "object") { 41 | extend(exports, jasmineInterface); 42 | } else { 43 | extend(window, jasmineInterface); 44 | } 45 | 46 | /** 47 | * ## Runner Parameters 48 | * 49 | * More browser specific code - wrap the query string in an object and to allow for getting/setting parameters from the runner user interface. 50 | */ 51 | 52 | var queryString = new jasmine.QueryString({ 53 | getWindowLocation: function() { return window.location; } 54 | }); 55 | 56 | var catchingExceptions = queryString.getParam("catch"); 57 | env.catchExceptions(typeof catchingExceptions === "undefined" ? true : catchingExceptions); 58 | 59 | /** 60 | * ## Reporters 61 | * The `HtmlReporter` builds all of the HTML UI for the runner page. This reporter paints the dots, stars, and x's for specs, as well as all spec names and all failures (if any). 62 | */ 63 | var htmlReporter = new jasmine.HtmlReporter({ 64 | env: env, 65 | onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, 66 | getContainer: function() { return document.body; }, 67 | createElement: function() { return document.createElement.apply(document, arguments); }, 68 | createTextNode: function() { return document.createTextNode.apply(document, arguments); }, 69 | timer: new jasmine.Timer() 70 | }); 71 | 72 | /** 73 | * The `jsApiReporter` also receives spec results, and is used by any environment that needs to extract the results from JavaScript. 74 | */ 75 | env.addReporter(jasmineInterface.jsApiReporter); 76 | env.addReporter(htmlReporter); 77 | 78 | /** 79 | * Filter which specs will be run by matching the start of the full name against the `spec` query param. 80 | */ 81 | var specFilter = new jasmine.HtmlSpecFilter({ 82 | filterString: function() { return queryString.getParam("spec"); } 83 | }); 84 | 85 | env.specFilter = function(spec) { 86 | return specFilter.matches(spec.getFullName()); 87 | }; 88 | 89 | /** 90 | * Setting up timing functions to be able to be overridden. Certain browsers (Safari, IE 8, phantomjs) require this hack. 91 | */ 92 | window.setTimeout = window.setTimeout; 93 | window.setInterval = window.setInterval; 94 | window.clearTimeout = window.clearTimeout; 95 | window.clearInterval = window.clearInterval; 96 | 97 | /** 98 | * ## Execution 99 | * 100 | * Replace the browser window's `onload`, ensure it's called, and then run all of the loaded specs. This includes initializing the `HtmlReporter` instance and then executing the loaded Jasmine environment. All of this will happen after all of the specs are loaded. 101 | */ 102 | var currentWindowOnload = window.onload; 103 | 104 | window.onload = function() { 105 | if (currentWindowOnload) { 106 | currentWindowOnload(); 107 | } 108 | htmlReporter.initialize(); 109 | env.execute(); 110 | }; 111 | 112 | /** 113 | * Helper function for readability above. 114 | */ 115 | function extend(destination, source) { 116 | for (var property in source) destination[property] = source[property]; 117 | return destination; 118 | } 119 | 120 | }()); 121 | -------------------------------------------------------------------------------- /lib/jasmine-2.1.3/console.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2008-2014 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 | function getJasmineRequireObj() { 24 | if (typeof module !== 'undefined' && module.exports) { 25 | return exports; 26 | } else { 27 | window.jasmineRequire = window.jasmineRequire || {}; 28 | return window.jasmineRequire; 29 | } 30 | } 31 | 32 | getJasmineRequireObj().console = function(jRequire, j$) { 33 | j$.ConsoleReporter = jRequire.ConsoleReporter(); 34 | }; 35 | 36 | getJasmineRequireObj().ConsoleReporter = function() { 37 | 38 | var noopTimer = { 39 | start: function(){}, 40 | elapsed: function(){ return 0; } 41 | }; 42 | 43 | function ConsoleReporter(options) { 44 | var print = options.print, 45 | showColors = options.showColors || false, 46 | onComplete = options.onComplete || function() {}, 47 | timer = options.timer || noopTimer, 48 | specCount, 49 | failureCount, 50 | failedSpecs = [], 51 | pendingCount, 52 | ansi = { 53 | green: '\x1B[32m', 54 | red: '\x1B[31m', 55 | yellow: '\x1B[33m', 56 | none: '\x1B[0m' 57 | }, 58 | failedSuites = []; 59 | 60 | print('ConsoleReporter is deprecated and will be removed in a future version.'); 61 | 62 | this.jasmineStarted = function() { 63 | specCount = 0; 64 | failureCount = 0; 65 | pendingCount = 0; 66 | print('Started'); 67 | printNewline(); 68 | timer.start(); 69 | }; 70 | 71 | this.jasmineDone = function() { 72 | printNewline(); 73 | for (var i = 0; i < failedSpecs.length; i++) { 74 | specFailureDetails(failedSpecs[i]); 75 | } 76 | 77 | if(specCount > 0) { 78 | printNewline(); 79 | 80 | var specCounts = specCount + ' ' + plural('spec', specCount) + ', ' + 81 | failureCount + ' ' + plural('failure', failureCount); 82 | 83 | if (pendingCount) { 84 | specCounts += ', ' + pendingCount + ' pending ' + plural('spec', pendingCount); 85 | } 86 | 87 | print(specCounts); 88 | } else { 89 | print('No specs found'); 90 | } 91 | 92 | printNewline(); 93 | var seconds = timer.elapsed() / 1000; 94 | print('Finished in ' + seconds + ' ' + plural('second', seconds)); 95 | printNewline(); 96 | 97 | for(i = 0; i < failedSuites.length; i++) { 98 | suiteFailureDetails(failedSuites[i]); 99 | } 100 | 101 | onComplete(failureCount === 0); 102 | }; 103 | 104 | this.specDone = function(result) { 105 | specCount++; 106 | 107 | if (result.status == 'pending') { 108 | pendingCount++; 109 | print(colored('yellow', '*')); 110 | return; 111 | } 112 | 113 | if (result.status == 'passed') { 114 | print(colored('green', '.')); 115 | return; 116 | } 117 | 118 | if (result.status == 'failed') { 119 | failureCount++; 120 | failedSpecs.push(result); 121 | print(colored('red', 'F')); 122 | } 123 | }; 124 | 125 | this.suiteDone = function(result) { 126 | if (result.failedExpectations && result.failedExpectations.length > 0) { 127 | failureCount++; 128 | failedSuites.push(result); 129 | } 130 | }; 131 | 132 | return this; 133 | 134 | function printNewline() { 135 | print('\n'); 136 | } 137 | 138 | function colored(color, str) { 139 | return showColors ? (ansi[color] + str + ansi.none) : str; 140 | } 141 | 142 | function plural(str, count) { 143 | return count == 1 ? str : str + 's'; 144 | } 145 | 146 | function repeat(thing, times) { 147 | var arr = []; 148 | for (var i = 0; i < times; i++) { 149 | arr.push(thing); 150 | } 151 | return arr; 152 | } 153 | 154 | function indent(str, spaces) { 155 | var lines = (str || '').split('\n'); 156 | var newArr = []; 157 | for (var i = 0; i < lines.length; i++) { 158 | newArr.push(repeat(' ', spaces).join('') + lines[i]); 159 | } 160 | return newArr.join('\n'); 161 | } 162 | 163 | function specFailureDetails(result) { 164 | printNewline(); 165 | print(result.fullName); 166 | 167 | for (var i = 0; i < result.failedExpectations.length; i++) { 168 | var failedExpectation = result.failedExpectations[i]; 169 | printNewline(); 170 | print(indent(failedExpectation.message, 2)); 171 | print(indent(failedExpectation.stack, 2)); 172 | } 173 | 174 | printNewline(); 175 | } 176 | 177 | function suiteFailureDetails(result) { 178 | for (var i = 0; i < result.failedExpectations.length; i++) { 179 | printNewline(); 180 | print(colored('red', 'An error was thrown in an afterAll')); 181 | printNewline(); 182 | print(colored('red', 'AfterAll ' + result.failedExpectations[i].message)); 183 | 184 | } 185 | printNewline(); 186 | } 187 | } 188 | 189 | return ConsoleReporter; 190 | }; 191 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Assignment 2 | 3 | Your assignment will be to build your own jQuery library through a series of different steps. This will help you learn JavaScript. 4 | All tasks are jQuery equivalent methods. 5 | 6 | To be clear, you cannot use jQuery. You must use standard JavaScript methods to create **jQuery equivalent methods**. 7 | 8 | Rules: 9 | 10 | 1. every task should be in its own folder 11 | * every task should be tested with [jasmine](http://jasmine.github.io/). Specs should be in the task folder named spec 12 | * every task should be completed in order. Do not skip ahead, as tasks build upon one another 13 | 14 | You should solve one task at a time. Every task is described by specs and your implementation must pass all of them. 15 | It would be good for you to have one or more mentors, but this is not mandatory. They should go through your code and give you feedback on what is good, what is bad, and how you can write it better. Also, a mentor will help keep you on task, minimize your frustrations, and maximize the value of this project. 16 | 17 | # Tasks 18 | 19 | All tasks should be compatible with the W3C standard. 20 | Everything needs to work in all major modern browsers. 21 | You do not need to make them backwards compatible with older IE browsers. 22 | 23 | Helpful references: 24 | 25 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/JavaScript) 26 | * [DevDocs](http://devdocs.io/) 27 | * [Can I Use](http://caniuse.com/) 28 | 29 | 30 | 31 | ## 0. Example 32 | 33 | You need to write a function that computes n-th Fibonacci number. 34 | 35 | The code can be found in repository /00.example/src. 36 | 37 | Also, specs for this task can be found in /00.example/spec. 38 | 39 | 40 | ## 1. Simple Selector function 41 | 42 | Terms: 43 | 44 | * Selector - selects which elements in the DOM to work with. 45 | 46 | References: 47 | 48 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Getting_started/Selectors) 49 | * [Minimal sizzle selector](http://sizzlejs.com/) 50 | 51 | Description: 52 | 53 | * Can select elements based on one of three items: 54 | * the given tag name 55 | * class name 56 | * or ID 57 | 58 | * Should return an array of selected HTML elements 59 | 60 | Examples: 61 | 62 | ```JavaScript 63 | domSelector('#some-id'); 64 | domSelector('.some-class'); 65 | domSelector('some-tag'); 66 | ``` 67 | 68 | ## 2. CSS manipulation 69 | 70 | Terms: 71 | 72 | * CSS (cascading style sheets) is a stylesheet language used to describe the presentation of a document written in HTML or XML 73 | 74 | References: 75 | 76 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/CSS) 77 | 78 | Description: 79 | 80 | * Should be able to set/change single or multiple CSS property values for selected elements, and also get the value of any existing CSS property 81 | 82 | Examples: 83 | 84 | ```JavaScript 85 | // set single property 86 | cssProp(htmlElement, cssProperty, value); 87 | 88 | // set multiple properties 89 | cssProp(htmlElement, {cssProperty: value, cssProperty: value}); 90 | 91 | // get CSS property value 92 | cssProp(htmlElement, cssProperty); 93 | ``` 94 | 95 | ## 3. CSS class manipulation 96 | 97 | Terms: 98 | 99 | * CSS class selectors match an element based on the contents of the element's class attribute, one of which must match exactly the class name given 100 | 101 | References: 102 | 103 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/CSS/Class_selectors) 104 | 105 | Description: 106 | 107 | * Should either add, remove, or toggle a named Class to the matched element(s), or else determine if that element is assigned that named class 108 | 109 | Examples: 110 | 111 | ```JavaScript 112 | cssClass.add(htmlElement, className); 113 | cssClass.remove(htmlElement, className); 114 | cssClass.toggle(htmlElement, className); 115 | cssClass.has(htmlElement, className); 116 | ``` 117 | 118 | ## 4. DOM manipulation 119 | 120 | Terms: 121 | 122 | * "The Document Object Model (DOM) is a programming interface for HTML, XML and SVG documents. It provides a structured representation of the document (a tree) and it defines a way that the structure can be accessed from programs so that they can change the document structure, style and content." 123 | 124 | References: 125 | 126 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/API/)Document_Object_Model 127 | 128 | Description: 129 | 130 | * Should manipulate the DOM in the specified manner: 131 | * remove an element 132 | * append an element to the DOM 133 | * insert an element in the DOM after a specified element 134 | * insert an element in the DOM before a specified element 135 | * get the value of a selected element 136 | 137 | Examples: 138 | 139 | ```JavaScript 140 | dom.remove(element); 141 | dom.append(targetElement, element); 142 | dom.after(targetElement, element); 143 | dom.prepend(targetElement, element); 144 | dom.before(targetElement, element); 145 | dom.val(targetElement); 146 | ``` 147 | 148 | ## 5. Ajax request function 149 | 150 | Terms: 151 | 152 | * Ajax stands for Asynchronous JavaScript and XML. It is a model, combining multiple technologies so web applications are able to make quick, incremental updates to the user interface without reloading the entire browser page 153 | * All data is sent as JSON 154 | 155 | References: 156 | 157 | * [Mozilla Developer Network](https://developer.mozilla.org/en/docs/AJAX) 158 | 159 | Description: 160 | 161 | * should make a successful Ajax request and post 162 | * should call a custom function on either success or failure (with a custom context) 163 | * should call a custom function when a request is completed (with a custom context) 164 | 165 | Examples: 166 | 167 | ```JavaScript 168 | ajaxReq(url, options); 169 | 170 | ajaxReq(url, { 171 | method: 'POST', 172 | data: {}, 173 | context: this, 174 | failure: function() {}, 175 | success: function() {}, 176 | complete: function() {} 177 | }); 178 | ``` 179 | 180 | ## 6. Event Listeners 181 | 182 | Terms: 183 | 184 | * Event Listeners attach event handlers to elements and listen for specified events. They specify what to do when specific events register on those elements 185 | 186 | References: 187 | 188 | * [Mozilla Developer Network](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget.addEventListener) 189 | 190 | 191 | Description: 192 | 193 | * should register listeners for single or multiple events on the specified element and apply a callback 194 | * should be able to remove listener callbacks from specified elements 195 | 196 | Examples: 197 | 198 | ```JavaScript 199 | eventListener.on(element, event, callback); 200 | 201 | // removes a specific callback on an element of the event type 202 | eventListener.off(element, event, callback); 203 | 204 | // removes all callbacks on an element of the event type 205 | eventListener.off(element, event); 206 | 207 | // removes all callbacks on an element 208 | eventListener.off(element); 209 | ``` 210 | 211 | ### 6.1. Additional Event Listener trigger 212 | 213 | Description: 214 | 215 | * Should trigger a specific event on a selected element 216 | 217 | Example: 218 | 219 | eventListener.trigger(element, event); 220 | 221 | 222 | ### 6.2. Event delegation 223 | 224 | Description: 225 | 226 | * Delegate a specific event to an element with the specified class name 227 | 228 | Example: 229 | 230 | ```JavaScript 231 | eventListener 232 | .delegate(monitoredElement, className, event, callback); 233 | ``` 234 | 235 | ## 7. Make learnQuery! 236 | 237 | Create your own learnQuery library using the knowledge gained from making the previous functions. It should include all the functions you created in the previous tasks, and it should look and function similar to jQuery. 238 | 239 | You have already created the functionality in the previous tasks. Now you simply need to provide a way to implement them. 240 | 241 | Your solution **must** support **chaining**! 242 | 243 | **Hint**: Pay attention to scope, closures, and context. 244 | 245 | Example: 246 | 247 | ```JavaScript 248 | learnQuery('.thisClass') 249 | .on('click', callback) 250 | .removeClass('thisClass') 251 | .addClass('anotherClass'); 252 | ``` 253 | 254 | # FAQ 255 | 256 | * What "affix()" does? 257 | 258 | Affix accepts CSS selectors as arguments and adds those elements to the DOM. 259 | Details: https://github.com/searls/jasmine-fixture 260 | 261 | # License 262 | LearnQuery is released under the [MIT license](http://www.opensource.org/licenses/MIT). 263 | 264 | # Credits 265 | 266 | Maintained and sponsored by 267 | [Infinum] (http://www.infinum.co). 268 | 269 | 270 | -------------------------------------------------------------------------------- /06.event_listeners/spec/eventListeners.js: -------------------------------------------------------------------------------- 1 | /*global affix*/ 2 | /*global eventListener*/ 3 | 4 | describe('EventListeners', function() { 5 | 'use strict'; 6 | 7 | var $selectedElement, selectedElement, methods; 8 | 9 | beforeEach(function() { 10 | affix('.learn-query-testing #toddler .hidden.toy+h1[class="title"]+span[class="subtitle"]+span[class="subtitle"]+input[name="toyName"][value="cuddle bunny"]+input[class="creature"][value="unicorn"]+.hidden+.infinum[value="awesome cool"]'); 11 | 12 | methods = { 13 | showLove: function() { 14 | console.log('<3 JavaScript <3'); 15 | }, 16 | 17 | giveLove: function() { 18 | console.log('==> JavaScript ==>'); 19 | return '==> JavaScript ==>'; 20 | } 21 | }; 22 | 23 | spyOn(methods, 'showLove'); 24 | spyOn(methods, 'giveLove'); 25 | 26 | $selectedElement = $('#toddler'); 27 | selectedElement = $selectedElement[0]; 28 | }); 29 | 30 | it('should be able to add a click event to an HTML element', function() { 31 | eventListener.on(selectedElement, 'click', methods.showLove); 32 | 33 | var eClick = createNewClickEvent(); 34 | selectedElement.dispatchEvent(eClick); 35 | 36 | expect(methods.showLove).toHaveBeenCalled(); 37 | }); 38 | 39 | it('should be able to add the same event+callback two times to an HTML element', function() { 40 | eventListener.on(selectedElement, 'click', methods.showLove); 41 | eventListener.on(selectedElement, 'click', methods.showLove); 42 | 43 | var eClick = createNewClickEvent(); 44 | selectedElement.dispatchEvent(eClick); 45 | 46 | expect(methods.showLove.calls.count()).toEqual(2); 47 | }); 48 | 49 | 50 | it('should be able to add the same callback for two different events to an HTML element', function() { 51 | eventListener.on(selectedElement, 'click', methods.showLove); 52 | eventListener.on(selectedElement, 'hover', methods.showLove); 53 | 54 | var eClick = createNewClickEvent(); 55 | selectedElement.dispatchEvent(eClick); 56 | 57 | var eHover = new Event('hover'); 58 | selectedElement.dispatchEvent(eHover); 59 | 60 | expect(methods.showLove.calls.count()).toEqual(2); 61 | }); 62 | 63 | it('should be able to add two different callbacks for same event to an HTML element', function() { 64 | eventListener.on(selectedElement, 'click', methods.showLove); 65 | eventListener.on(selectedElement, 'click', methods.giveLove); 66 | 67 | var eClick = createNewClickEvent(); 68 | selectedElement.dispatchEvent(eClick); 69 | 70 | expect(methods.showLove.calls.count()).toEqual(1); 71 | expect(methods.giveLove.calls.count()).toEqual(1); 72 | }); 73 | 74 | it('should be able to remove one event handler of an HTML element', function() { 75 | $selectedElement.off(); 76 | 77 | eventListener.on(selectedElement, 'click', methods.showLove); 78 | eventListener.on(selectedElement, 'click', methods.giveLove); 79 | eventListener.off(selectedElement, 'click', methods.showLove); 80 | 81 | var eClick = createNewClickEvent(); 82 | selectedElement.dispatchEvent(eClick); 83 | 84 | expect(methods.showLove.calls.count()).toEqual(0); 85 | expect(methods.giveLove.calls.count()).toEqual(1); 86 | }); 87 | 88 | it('should be able to remove all click events of a HTML element', function() { 89 | $selectedElement.off(); 90 | 91 | eventListener.on(selectedElement, 'click', methods.showLove); 92 | eventListener.on(selectedElement, 'click', methods.giveLove); 93 | eventListener.on(selectedElement, 'hover', methods.showLove); 94 | 95 | eventListener.off(selectedElement, 'click'); 96 | 97 | var eClick = createNewClickEvent(); 98 | selectedElement.dispatchEvent(eClick); 99 | 100 | var eHover = new Event('hover'); 101 | selectedElement.dispatchEvent(eHover); 102 | 103 | expect(methods.showLove.calls.count()).toEqual(1); 104 | expect(methods.giveLove).not.toHaveBeenCalled(); 105 | }); 106 | 107 | it('should be able to remove all events of a HTML element', function() { 108 | $selectedElement.off(); 109 | 110 | eventListener.on(selectedElement, 'click', methods.showLove); 111 | eventListener.on(selectedElement, 'click', methods.giveLove); 112 | eventListener.on(selectedElement, 'hover', methods.showLove); 113 | 114 | eventListener.off(selectedElement); 115 | 116 | var eClick = createNewClickEvent(); 117 | selectedElement.dispatchEvent(eClick); 118 | 119 | var eHover = new Event('hover'); 120 | selectedElement.dispatchEvent(eHover); 121 | 122 | expect(methods.showLove).not.toHaveBeenCalled(); 123 | expect(methods.giveLove).not.toHaveBeenCalled(); 124 | }); 125 | 126 | it('should trigger a click event on a HTML element', function() { 127 | $selectedElement.off(); 128 | $selectedElement.on('click', methods.showLove); 129 | 130 | eventListener.trigger(selectedElement, 'click'); 131 | 132 | expect(methods.showLove.calls.count()).toBe(1); 133 | }); 134 | 135 | it('should delegate an event to elements with a given css class name', function() { 136 | eventListener.delegate(selectedElement, 'title', 'click', methods.showLove); 137 | var titleEl = document.querySelector('h1.title'); 138 | 139 | var eClick = createNewClickEvent(); 140 | titleEl.dispatchEvent(eClick); 141 | 142 | expect(methods.showLove.calls.count()).toEqual(1); 143 | }); 144 | 145 | it('should not delegate an event to elements without a given css class name', function() { 146 | eventListener.delegate(selectedElement, 'title', 'click', methods.showLove); 147 | var titleEl = document.querySelector('h1.title'); 148 | var subtitleEl = document.querySelector('.subtitle'); 149 | 150 | var eClickTitle = createNewClickEvent(); 151 | var eClickSubtitle = createNewClickEvent(); 152 | titleEl.dispatchEvent(eClickTitle); 153 | subtitleEl.dispatchEvent(eClickSubtitle); 154 | 155 | expect(methods.showLove.calls.count()).toEqual(1); 156 | }); 157 | 158 | it('should delegate an event to elements that are added to the DOM to after delegate call', function() { 159 | eventListener.delegate(selectedElement, 'new-element-class', 'click', methods.showLove); 160 | 161 | var newElement = document.createElement('div'); 162 | newElement.className = 'new-element-class'; 163 | $selectedElement.append(newElement); 164 | 165 | var eClick = createNewClickEvent(); 166 | newElement.dispatchEvent(eClick); 167 | 168 | expect(methods.showLove.calls.count()).toEqual(1); 169 | }); 170 | 171 | it('should trigger delegated event handler when clicked on an element inside a targeted element', function() { 172 | eventListener.delegate(selectedElement, 'title', 'click', methods.showLove); 173 | 174 | var newElement = document.createElement('div'); 175 | newElement.className = 'new-element-class'; 176 | $selectedElement.append(newElement); 177 | 178 | $('h1.title').append(newElement); 179 | 180 | var eClick = createNewClickEvent(); 181 | newElement.dispatchEvent(eClick); 182 | 183 | expect(methods.showLove.calls.count()).toEqual(1); 184 | }); 185 | 186 | it('should not trigger delegated event handler if clicked on container of delegator', function() { 187 | var $targetElement = $('

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