├── .travis.yml
├── test
├── lib
│ └── jasmine-2.3.4
│ │ ├── jasmine_favicon.png
│ │ ├── boot.js
│ │ ├── console.js
│ │ ├── jasmine-html.js
│ │ ├── jasmine.css
│ │ └── jasmine.js
├── tests.html
└── spec
│ └── json-formdata-spec.js
├── .jshintrc
├── .editorconfig
├── examples
├── working-draft-examples
│ ├── files.html
│ ├── append-syntax.html
│ ├── such-deep.html
│ ├── sparse-arrays.html
│ ├── multiple-values.html
│ ├── deeper-structure.html
│ ├── even-deeper.html
│ ├── basic-keys.html
│ └── merge-behavior.html
├── submit-callback.html
└── submit.html
├── LICENSE
├── README.md
├── run-jasmine.js
└── src
└── json-formdata.js
/.travis.yml:
--------------------------------------------------------------------------------
1 | script: phantomjs run-jasmine.js ./test/tests.html
2 |
--------------------------------------------------------------------------------
/test/lib/jasmine-2.3.4/jasmine_favicon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/roman01la/JSONFormData/HEAD/test/lib/jasmine-2.3.4/jasmine_favicon.png
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/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/append-syntax.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSONFormData Example - Append Syntax
6 |
7 |
12 |
13 |
14 |
15 |
19 |
20 |
21 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/merge-behavior.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | JSONFormData Example - Merge Behavior
6 |
7 |
12 |
13 |
14 |
15 |
23 |
24 |
25 |
34 |
35 |
36 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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 | '' +
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