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