Small utility for serialising JS objects to query strings for use in URLs

js-query-error-spec.js 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. var querify = require("../lib/index.js");
  2. describe("Object -> Query String W/ Errors", function () {
  3. it("Should fail with functions or Symbols", function () {
  4. var qs_object = {
  5. f: function() { /* istanbul ignore next */
  6. console.log("Hello World!");
  7. },
  8. s: Symbol("foo")
  9. };
  10. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
  11. });
  12. it("Should fail for nulls", function () {
  13. var qs_object = {
  14. str: "mystr",
  15. second_str: null
  16. };
  17. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=mystr");
  18. });
  19. it("Should fail for undefined", function () {
  20. var qs_object = {
  21. str: "a string",
  22. second_str: undefined
  23. };
  24. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=a%20string");
  25. });
  26. it("Should fail when trying to use non-objects", function () {
  27. var qs_object = "str";
  28. var qs_object2 = 2;
  29. var qs_object3 = function () { console.log("Hello World!"); };
  30. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
  31. expect(querify.convert(qs_object2, { warn_on_invalid: true })).toBe("");
  32. expect(querify.convert(qs_object3, { warn_on_invalid: true })).toBe("");
  33. });
  34. });