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

js-query-error-spec.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839
  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() { console.log("Hello World!"); },
  6. s: Symbol("foo")
  7. };
  8. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
  9. });
  10. it("Should fail for nulls", function () {
  11. var qs_object = {
  12. str: "mystr",
  13. second_str: null
  14. };
  15. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=mystr");
  16. });
  17. it("Should fail for undefined", function () {
  18. var qs_object = {
  19. str: "a string",
  20. second_str: undefined
  21. };
  22. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("?str=a%20string");
  23. });
  24. it("Should fail when trying to use non-objects", function () {
  25. var qs_object = "str";
  26. var qs_object2 = 2;
  27. var qs_object3 = function () { console.log("Hello World!"); };
  28. expect(querify.convert(qs_object, { warn_on_invalid: true })).toBe("");
  29. expect(querify.convert(qs_object2, { warn_on_invalid: true })).toBe("");
  30. expect(querify.convert(qs_object3, { warn_on_invalid: true })).toBe("");
  31. });
  32. });