Pārlūkot izejas kodu

Removing warnings when running the test and fix a bug when warnings are disabled and non-objects are passed as arguments

Matt Coles 9 gadi atpakaļ
vecāks
revīzija
dcfdc13300
4 mainītis faili ar 17 papildinājumiem un 17 dzēšanām
  1. 5 5
      lib/index.js
  2. 1 1
      lib/index.min.js
  3. 6 6
      spec/js-query-error-spec.js
  4. 5 5
      src/index.js

+ 5 - 5
lib/index.js

9
   },
9
   },
10
 
10
 
11
   convert: function convert(data, options) {
11
   convert: function convert(data, options) {
12
+    if (options === undefined) {
13
+      options = {};
14
+    }
15
+    options = this._merge_options(this._defaults, options);
12
     if ((typeof data === "undefined" ? "undefined" : _typeof(data)) === 'object') {
16
     if ((typeof data === "undefined" ? "undefined" : _typeof(data)) === 'object') {
13
-      if (options === undefined) {
14
-        options = {};
15
-      }
16
-      options = this._merge_options(this._defaults, options);
17
       var result = "?";
17
       var result = "?";
18
       Object.keys(data).map(function (query_key) {
18
       Object.keys(data).map(function (query_key) {
19
         var query_data = data[query_key];
19
         var query_data = data[query_key];
50
     } else {
50
     } else {
51
       if (options.warn_on_invalid) {
51
       if (options.warn_on_invalid) {
52
         console.warn("Attempted to convert non-object to query string!");
52
         console.warn("Attempted to convert non-object to query string!");
53
-        return "";
54
       }
53
       }
54
+      return "";
55
     }
55
     }
56
   },
56
   },
57
 
57
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
lib/index.min.js


+ 6 - 6
spec/js-query-error-spec.js

9
       },
9
       },
10
       s: Symbol("foo")
10
       s: Symbol("foo")
11
     };
11
     };
12
-    expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
12
+    expect(querify.convert(qs_object)).toBe("");
13
   });
13
   });
14
 
14
 
15
   it("Should fail for nulls", function () {
15
   it("Should fail for nulls", function () {
17
       str: "mystr",
17
       str: "mystr",
18
       second_str: null
18
       second_str: null
19
     };
19
     };
20
-    expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=mystr");
20
+    expect(querify.convert(qs_object)).toBe("?str=mystr");
21
   });
21
   });
22
 
22
 
23
   it("Should fail for undefined", function () {
23
   it("Should fail for undefined", function () {
25
       str: "a string",
25
       str: "a string",
26
       second_str: undefined
26
       second_str: undefined
27
     };
27
     };
28
-    expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=a%20string");
28
+    expect(querify.convert(qs_object)).toBe("?str=a%20string");
29
   });
29
   });
30
 
30
 
31
   it("Should fail when trying to use non-objects", function () {
31
   it("Should fail when trying to use non-objects", function () {
32
     var qs_object = "str";
32
     var qs_object = "str";
33
     var qs_object2 = 2;
33
     var qs_object2 = 2;
34
     var qs_object3 = function () { console.log("Hello World!"); };
34
     var qs_object3 = function () { console.log("Hello World!"); };
35
-    expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
36
-    expect(querify.convert(qs_object2, { warn_on_invalid: true })).toBe("");
37
-    expect(querify.convert(qs_object3, { warn_on_invalid: true })).toBe("");
35
+    expect(querify.convert(qs_object)).toBe("");
36
+    expect(querify.convert(qs_object2)).toBe("");
37
+    expect(querify.convert(qs_object3)).toBe("");
38
   });
38
   });
39
 
39
 
40
 });
40
 });

+ 5 - 5
src/index.js

6
   },
6
   },
7
 
7
 
8
   convert: function (data, options) {
8
   convert: function (data, options) {
9
+    if (options === undefined) {
10
+      options = {};
11
+    }
12
+    options = this._merge_options(this._defaults, options);
9
     if (typeof data === 'object') {
13
     if (typeof data === 'object') {
10
-      if (options === undefined) {
11
-        options = {};
12
-      }
13
-      options = this._merge_options(this._defaults, options);
14
       let result = "?";
14
       let result = "?";
15
       Object.keys(data).map(function (query_key) {
15
       Object.keys(data).map(function (query_key) {
16
         let query_data = data[query_key];
16
         let query_data = data[query_key];
47
     } else {
47
     } else {
48
       if (options.warn_on_invalid) {
48
       if (options.warn_on_invalid) {
49
         console.warn("Attempted to convert non-object to query string!");
49
         console.warn("Attempted to convert non-object to query string!");
50
-        return "";
51
       }
50
       }
51
+      return "";
52
     }
52
     }
53
   },
53
   },
54
 
54